﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using FDEE.Model;
using FDEEInterface;
using FDEEPublicFunc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FDEEDrawingModels
{
    public class PloterTable
    {
        static string _dwgPath = "";//构造物
        static string _blcName = "MI12";
        static double A3Height = 297 - 10 - Extensions.bottomHeight;
        static double intervalHeight = 26;//小于块高度设置高度
        static double tbH = 0;

        static double lastMegerHeight = 0;

        #region 承台
        /// <summary>
        /// 承台
        /// </summary>
        /// <param name="db"></param>
        /// <param name="eType"></param>
        /// <param name="listRebar"></param>
        /// <param name="dwgPath"></param>
        /// <param name="typeName"></param>
        /// <param name="structureName"></param>
        /// <param name="type"></param>
        /// <param name="eConType"></param>
        /// <param name="conValue"></param>
        /// <param name="scale"></param>
        public static void DrawingFootingTable(Database db, MemberBase ret, EStructure eType, string dwgPath,
            string typeName, string structureName, FDEE.Model.eSubType type, int scale = 1, string tkPath = "")
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            _dwgPath = dwgPath;
            structureName = ret.TypeName;
            Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin;
            Point2d M1 = CT.Convert2D(0, -2 * scale);

            #region 分页处理
            List<RebarCollection> divDic = new List<RebarCollection>();
            CalcCloumPage(ret.RebarList, scale, ref divDic);
            #endregion

            DrawFootingRebar(db,dwgPath,typeName,type,20,tkPath);

            #region 绘制表格
            Table lasTb = new Table();
            for (int i = 0; i < divDic.Count; i++)
            {
                ext = new Extents2d(Point2d.Origin.Convert2D(420 * i), Point2d.Origin);
                lasTb = DrawFootTable(db, ref ext, M1.Convert3D(), divDic[i].Count + 2,
                    Extensions.curFont, scale, divDic[i], typeName, structureName, type, i);
                Extents2d extMerge = new Extents2d();

                if (i == 0)
                {
                    // 绘制合并表格
                    RebarCollection listBack = new RebarCollection();
                    listBack = ret.RebarList;
                    List<string> mergeList = new List<string>();
                    mergeList.Add("Materials");
                    mergeList.Add("Materials");
                    mergeList.Add("Unit");
                    mergeList.Add("Weight(kg)");
                    mergeList.Add("Total(kg)");

                    Point3d pt = M1.Convert3D(0, -lasTb.Height - 40 * scale);
                    Table tb = PloterTable.DrawMergeFootingTable(db, ret, eType, ref extMerge, pt, mergeList,
                        Extensions.curFont, scale);
                    double width = 0;
                    double height = 0;
                    if (tb != null)
                    {
                        width = tb.Width;
                        height = tb.Height;

                        string str1 = string.Format("QUANTITIES OF FOOTING \"{0}\"", structureName);
                        string str2 = string.Format("(COLUMN HEIGHT {0})", Common.GetPierHeightDes(typeName, type));
                        TextPloter.PrintScaleDoubleSideText(db, pt.Convert2D(width / 2, 8 * scale), 3, str1, str2, ref extMerge, scale, Extensions.curFont);
                    }
                    Common.CreateLayoutNew(db, "承台", ext, extMerge, scale, 1, 0, i, false, tkPath);
                    //Common.CreateLayout(db, "承台" + i, ext, extMerge, scale, 1,false,tkPath);
                }
                else
                {
                    Common.CreateLayoutNew(db, "承台", ext, extMerge, scale, 1, 0, i, false, tkPath);
                    //Common.CreateLayout(db, "承台" + i, ext, extMerge, scale, 1, false, tkPath);
                }
            }
            #endregion
        }

        public static void DrawFootingRebar(Database db, string dwgPath,
string typeName, FDEE.Model.eSubType type, double scale = 1, string tkPath = "")
        {
            try
            {
                _dwgPath = dwgPath;
                string directoryName = System.IO.Path.GetDirectoryName(_dwgPath);
                string reberBlockPath = directoryName + @"\FootingBlock.dwg";//构造物
                #region 插入钢筋
                List<Extents2d> exts = new List<Extents2d>();
                DrawingFootingRebar(db, Point3d.Origin.Convert3D(420 * 0.3, 297), typeName, type, scale, ref exts);
                if (exts.Count > 0)
                {
                    for (int i = 0; i < exts.Count; i++)
                    {
                        if (typeName == "FPTM1" || typeName == "F1PTM2" || typeName == "F2PTM2" || typeName == "FPTM1S" || typeName == "FPTM2S" || typeName == "FPTM3S" || typeName == "FPTM3U")
                            Common.CreateLayoutNew(db, "承台", exts[i], 1, 1, -1, i, false, tkPath);
                        else if (typeName.Contains("PE"))
                            Common.CreateLayoutNew(db, "承台", exts[i], 1, 1, -1, i, false, tkPath);
                        else
                        {
                            Common.CreateLayoutNew(db, "承台", exts[i], 1, 1, -1, i, false, tkPath);
                        }

                        _blcName = typeName.Replace("-", "");
                        if (typeName.Contains("FPE21"))
                            _blcName = typeName.Replace("-", "").Replace("A", "").Replace("B", "");
                        _blcName = "R" + _blcName;
                        db.CopyBlockFromFile(reberBlockPath, _blcName);

                        //if(typeName == "F1PTM2" || typeName == "F2PTM2")
                        //    _blcName = "RFPTM2";
                        if (typeName == "FPTM2S")
                            BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -1).Convert3D(355.26,244.67), 1, _blcName, reberBlockPath, 0,false);
                        else
                            BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -1).Convert3D(355.26, 249.57), 1, _blcName, reberBlockPath, 0, false);


                        _blcName ="MainMark";
                     
                        db.CopyBlockFromFile(reberBlockPath, _blcName);
                        BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -1).Convert3D(370.26, 230), 1, _blcName, reberBlockPath, 0, false);
                    }
                }
                #endregion
            }
            catch
            {

            }
        }

        public static void DrawingFootingRebar(Database db, Point3d startPoint, string typeName, FDEE.Model.eSubType type, double scale, ref List<Extents2d> exts)
        {
            Dictionary<string, Dictionary<string, string>> dicA = new Dictionary<string, Dictionary<string, string>>();
            Dictionary<string, string> dicT = new Dictionary<string, string>();
            string directoryName = System.IO.Path.GetDirectoryName(_dwgPath);
            string reberBlockPath = directoryName + @"\FootingBlock.dwg";//构造物
            if (typeName == "FPTM1" || typeName == "F1PTM2" || typeName == "F2PTM2" || typeName == "FPTM1S" || typeName == "FPTM2S" || typeName == "FPTM3S" || typeName == "FPTM3U")
            {
                //dicA = new Dictionary<string, Dictionary<string, string>>();
                //dicT = new Dictionary<string, string>();
                //_blcName = "平面钢束标注";
                //dicT.Add("1", "int");
                //dicA.Add("方向", dicT);
                //dicT = new Dictionary<string, string>();
               
                //dicT.Add("2", "double");
                //dicA.Add("引线长度", dicT);
                //db.CopyBlockFromFile(@"C:\Users\huajie\Desktop\块测试.dwg", _blcName);
                //Extents2d ext0 = new Extents2d(startPoint.Convert2D(0, -10), startPoint.Convert2D(0, -10));
                //BlockTool.InsertBlockReference(startPoint.Convert3D(-100, -10), scale, _blcName, reberBlockPath, dicA, dicA, ref ext0);

                dicA = new Dictionary<string, Dictionary<string, string>>();
                dicT = new Dictionary<string, string>();
                string val = Common.GetPierHeightDes(typeName, type);
                dicT.Add(val, "string");
                dicA.Add("ESUBTYPE", dicT);
                Extents2d ext = new Extents2d(startPoint.Convert2D(0,-10), startPoint.Convert2D(0,-10));
                _blcName = typeName;
                if (typeName == "FPTM1S" && type.ToString() == "D")
                    _blcName = typeName+"-D";
                db.CopyBlockFromFile(reberBlockPath, _blcName);
                //BlockTool.InsertBlockReference(startPoint.Convert3D(), scale, _blcName, _dwgPath,ref ext);
                if (typeName == "FPTM1" || typeName == "F1PTM2" || typeName == "F2PTM2" || typeName == "FPTM3S")
                    BlockTool.InsertBlockReference(startPoint.Convert3D(0,-10), scale, _blcName, reberBlockPath, dicA, null, ref ext);
                else if (typeName == "FPTM1S"|| typeName == "FPTM2S" || typeName == "FPTM3U")
                    BlockTool.InsertBlockReference(startPoint.Convert3D(0,-10), scale, _blcName, reberBlockPath, null, null, ref ext);
                double height = ext.L();
                double width = ext.L();
                Extents2d ext1 = new Extents2d(startPoint.Convert2D(width + 10, -10), startPoint.Convert2D(width + 10, -10));
                dicA = new Dictionary<string, Dictionary<string, string>>();
                dicT = new Dictionary<string, string>();
                string val1 = "\""+ "C-" + typeName.Replace("F1", "").Replace("F2", "").Replace("F", "") + "" + type.ToString()+ "\"";

                dicT.Add(val1, "string");
                dicA.Add("ECOLUMNTYPE", dicT);
                //ext = new Extents2d(startPoint.Convert2D(0,- height), startPoint.Convert2D(0, -height));
                _blcName = typeName.Replace("B", "") + "-1";
                db.CopyBlockFromFile(reberBlockPath, _blcName);
                //if (typeName == "FPTM1" || typeName == "F1PTM2" || typeName == "FPTM3S" || typeName == "FPTM3U")
                    BlockTool.InsertBlockReference(startPoint.Convert3D(width + 10, -10), scale, _blcName, reberBlockPath, dicA, null, ref ext1);
                double height1 = ext1.L();
                //else if (typeName == "FPTM1S"|| typeName == "F2PTM2"|| typeName == "FPTM2S")
                //    BlockTool.InsertBlockReference(startPoint.Convert3D(0, -height), scale, _blcName, _dwgPath, null, null, ref ext);
                ext.Add(ext1);
               
                _blcName = typeName.Replace("B", "") + "-2";
                db.CopyBlockFromFile(reberBlockPath, _blcName);
                if (typeName == "FPTM1" || typeName == "F1PTM2" || typeName == "FPTM3S" || typeName == "FPTM3U")
                    BlockTool.InsertBlockReference(startPoint.Convert3D(width + 10, -height1-12), scale, _blcName, reberBlockPath, dicA, null, ref ext);
                else if (typeName == "FPTM1S" || typeName == "F2PTM2" || typeName == "FPTM2S")
                    BlockTool.InsertBlockReference(startPoint.Convert3D(width  + 10, -height1 - 12), scale, _blcName, reberBlockPath, null, null, ref ext);
                string Contents =
              "Notes:\\P" +
              "    1. All dimensions are in m unless otherwise indicated.\\P" +
              "    2. The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer & architect before commencement of work.\\P" +
              "    3. All the produced unsuitable material shall be transport to the designate disposal area in a properly manner. \\P" +
              "    4. All the site activities and operations shall follow the requirement of the approved Health and Safety Managemen Plan strictly.\\P" +
              "    5. Concrete shall have the minimum 35MPa of cylinder compressive strength at 28 days.\\P" +
              "    6. Reinforcement steel shall have the minimum yield strength 500MPa.\\P" +
              "    7. Concrete cover shall be 0.100m at the bottom of footing, 0.075m at the top and 4 sides of footing, and 0.050m for column.";
                TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(-50, -height-10), Contents, 1, 2.5, width-10);

                exts.Add(ext);

            }
            else
            {
                if (typeName.Contains("PE")|| typeName.Contains("PTE") || typeName.Contains("PTL") || typeName.Contains("PL"))
                {
                    dicA = new Dictionary<string, Dictionary<string, string>>();
                    dicT = new Dictionary<string, string>();
                    string val = "(COLUMN HEIGHT " + Common.GetPierHeightDes(typeName, type) + ")";
                    dicT.Add(val, "string");
                    dicA.Add("ESUBTYPE", dicT);
                    Extents2d ext = new Extents2d(startPoint.Convert2D(0, -10), startPoint.Convert2D(0, -10));
                    _blcName = typeName.Replace("-","");
                    if (typeName.Contains("FPE21"))
                        _blcName = typeName.Replace("-", "").Replace("A", "").Replace("B", "");

                    db.CopyBlockFromFile(reberBlockPath, _blcName);

                    if (typeName.Replace("-", "") == "FPE12"|| typeName.Replace("-", "") == "FPE21" || typeName.Replace("-", "") == "FPE22" || typeName.Replace("-", "") == "FPE32"|| typeName.Replace("-", "") == "FPTL2" )
                        BlockTool.InsertBlockReference(startPoint.Convert3D(0, -10), scale, _blcName, reberBlockPath, dicA, null, ref ext);
                    else
                        BlockTool.InsertBlockReference(startPoint.Convert3D(0, -10), scale, _blcName, reberBlockPath, null, null, ref ext);
                    double height = ext.L();
                    double width = ext.L();
                    Extents2d ext1 = new Extents2d(startPoint.Convert2D(width + 10, -10), startPoint.Convert2D(width + 10, -10));
                    dicA = new Dictionary<string, Dictionary<string, string>>();
                    dicT = new Dictionary<string, string>();
                    if (typeName.Replace("-", "").Contains("FPE21"))
                        typeName = typeName.Replace("A", "").Replace("B", "");
                    string val1 = "Column \"" + "C-" + typeName.Replace("F1", "").Replace("F2", "").Replace("F", "") + type.ToString().Replace("M", "*") + "\"";

                    dicT.Add(val1, "string");
                    dicA.Add("ECOLUMNTYPE", dicT);
                    //ext = new Extents2d(startPoint.Convert2D(0,- height), startPoint.Convert2D(0, -height));
                    _blcName = typeName.Replace("-", "").Replace("B", "") + "-1";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    //if (typeName == "FPTM1" || typeName == "F1PTM2" || typeName == "FPTM3S" || typeName == "FPTM3U")
                    if(typeName.Replace("-", "") == "FPL2")
                        BlockTool.InsertBlockReference(startPoint.Convert3D(width + 10, -10), scale, _blcName, reberBlockPath, null, null, ref ext1);
                    else
                        BlockTool.InsertBlockReference(startPoint.Convert3D(width + 10, -10), scale, _blcName, reberBlockPath, dicA, null, ref ext1);
                    double height1 = ext1.L();

                    ext.Add(ext1);

                    _blcName = typeName.Replace("-", "").Replace("B", "") + "-2";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    if (typeName.Replace("-", "") == "FPL2")
                        BlockTool.InsertBlockReference(startPoint.Convert3D(width + 10, -height1 - 12), scale, _blcName, reberBlockPath, null, null, ref ext);
                    else
                        BlockTool.InsertBlockReference(startPoint.Convert3D(width + 10, -height1 - 12), scale, _blcName, reberBlockPath, dicA, null, ref ext);
                    string Contents =
                  "Notes:\\P" +
                  "    1. All dimensions are in m unless otherwise indicated.\\P" +
                  "    2. The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer & architect before commencement of work.\\P" +
                  "    3. All the produced unsuitable material shall be transport to the designate disposal area in a properly manner. \\P" +
                  "    4. All the site activities and operations shall follow the requirement of the approved Health and Safety Managemen Plan strictly.\\P" +
                  "    5. Concrete shall have the minimum 35MPa of cylinder compressive strength at 28 days.\\P" +
                  "    6. Reinforcement steel shall have the minimum yield strength 500MPa.\\P" +
                  "    7. Concrete cover shall be 0.100m at the bottom of footing, 0.075m at the top and 4 sides of footing, and 0.050m for column.";
                    TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(-50, -height - 10), Contents, 1, 2.5, width - 10);

                    exts.Add(ext);
                }
                else if(typeName.Contains("PME4"))
                {
                    dicA = new Dictionary<string, Dictionary<string, string>>();
                    dicT = new Dictionary<string, string>();
                    string val = "(COLUMN HEIGHT " + Common.GetPierHeightDes(typeName, type) + ")";
                    dicT.Add(val, "string");
                    dicA.Add("ESUBTYPE", dicT);
                    string val1 = "Column \"" + "C-" + typeName.Replace("F1", "").Replace("F2", "").Replace("F", "") + type.ToString().Replace("M", "*") + "\"";
                    dicT = new Dictionary<string, string>();
                    dicT.Add(val1, "string");
                    dicA.Add("ECOLUMNTYPE", dicT);
                    Extents2d ext = new Extents2d(startPoint.Convert2D(0, -10), startPoint.Convert2D(0, -10));
                    _blcName = typeName.Replace("-", "");
                  
                    db.CopyBlockFromFile(reberBlockPath, _blcName);

    
                    BlockTool.InsertBlockReference(startPoint.Convert3D(0, -10), scale, _blcName, reberBlockPath, dicA, null, ref ext);
                  
                    double height = ext.L();
                    double width = ext.L();
                    Extents2d ext1 = new Extents2d(startPoint.Convert2D(width , -10), startPoint.Convert2D(width , -10));
                    dicA = new Dictionary<string, Dictionary<string, string>>();
                    dicT = new Dictionary<string, string>();
                   
                    val1 = "Column \"" + "C-" + typeName.Replace("F1", "").Replace("F2", "").Replace("F", "") + type.ToString().Replace("M", "*") + "\"";

                    dicT.Add(val1, "string");
                    dicA.Add("ECOLUMNTYPE", dicT);
                    //ext = new Extents2d(startPoint.Convert2D(0,- height), startPoint.Convert2D(0, -height));
                    _blcName = typeName.Replace("-", "").Replace("B", "") + "-1";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    //if (typeName == "FPTM1" || typeName == "F1PTM2" || typeName == "FPTM3S" || typeName == "FPTM3U")
                    BlockTool.InsertBlockReference(startPoint.Convert3D(width , -10), scale, _blcName, reberBlockPath, dicA, null, ref ext1);
                    double height1 = ext1.L();

                    ext.Add(ext1);

                    _blcName = typeName.Replace("-", "").Replace("B", "") + "-2";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    if (typeName.Replace("-", "") == "FPME41")
                        BlockTool.InsertBlockReference(startPoint.Convert3D(width , -height1 - 12), scale, _blcName, reberBlockPath, dicA, null, ref ext);
                    else
                        BlockTool.InsertBlockReference(startPoint.Convert3D(width , -height1 - 12), scale, _blcName, reberBlockPath, null, null, ref ext);
                    string Contents =
                  "Notes:\\P" +
                  "    1. All dimensions are in m unless otherwise indicated.\\P" +
                  "    2. The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer & architect before commencement of work.\\P" +
                  "    3. All the produced unsuitable material shall be transport to the designate disposal area in a properly manner. \\P" +
                  "    4. All the site activities and operations shall follow the requirement of the approved Health and Safety Managemen Plan strictly.\\P" +
                  "    5. Concrete shall have the minimum 35MPa of cylinder compressive strength at 28 days.\\P" +
                  "    6. Reinforcement steel shall have the minimum yield strength 500MPa.\\P" +
                  "    7. Concrete cover shall be 0.100m at the bottom of footing, 0.075m at the top and 4 sides of footing, and 0.050m for column.";
                    TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(-50, -height - 10), Contents, 1, 2.5, width - 10);

                    exts.Add(ext);
                }
            }
        }
        #endregion

        #region 墩柱
        /// <summary>
        /// 墩柱
        /// </summary>
        /// <param name="db"></param>
        /// <param name="eType"></param>
        /// <param name="listRebar"></param>
        /// <param name="dwgPath"></param>
        /// <param name="typeName"></param>
        /// <param name="structureName"></param>
        /// <param name="type"></param>
        /// <param name="eConType"></param>
        /// <param name="conValue"></param>
        /// <param name="scale"></param>
        public static void DrawingColumnTable(Database db, MemberBase ret, EStructure eType, string dwgPath,
            string typeName, string structureName, string pierHeight, string pierName, FDEE.Model.eSubType type, int scale = 1, string title = "MAINLINE",string tkPath="")
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            _dwgPath = dwgPath;

            Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin;
            Point2d M1 = CT.Convert2D(0, -2 * scale);

            #region 分页处理
            List<RebarCollection> divDic = new List<RebarCollection>();
            CalcCloumPage(ret.RebarList, scale, ref divDic);
            //divDic.Add(ret.RebarList);
            #endregion

            #region 绘制表格
            Table lasTb = new Table();
            for (int i = 0; i < divDic.Count; i++)
            {
                ext = new Extents2d(Point2d.Origin.Convert2D(420 * i), Point2d.Origin);
                lasTb = DrawColumnTable(db, ref ext, M1.Convert3D(), divDic[i].Count + 2,
                    Extensions.curFont, scale, divDic[i], typeName, structureName, pierHeight, pierName, type, i);
                Extents2d extMerge = new Extents2d();
                //Common.CreateLayout(db, "基础数据表", ext, extMerge, scale, 1);

                if (i == divDic.Count - 1)
                {
                    // 绘制合并表格
                    RebarCollection listBack = new RebarCollection();
                    listBack = ret.RebarList;
                    List<string> mergeList = new List<string>();
                    mergeList.Add("Materials");
                    mergeList.Add("Materials");
                    mergeList.Add("Unit");
                    mergeList.Add("Weight(kg)");
                    mergeList.Add("Total(kg)");

                    Point3d pt = M1.Convert3D(420 * i + (lasTb.Width - 226) * 0.5, /*-20*/-lasTb.Height - 40 * scale);
                    Table tb = PloterTable.DrawMergeColumnTable(db, ret, eType, ref extMerge, pt, mergeList,
                        Extensions.curFont, scale);
                    double width = 0;
                    double height = 0;
                    if (tb != null)
                    {
                        width = tb.Width;
                        height = tb.Height;
                        string str1 = string.Format("PER COLUMN{0}{1}{2} QUANTITIES FOR {3} OF " + title + "(COLUMN HEIGHT={4}M)", "\"", structureName, "\"", pierName, pierHeight);

                        if (pierName.Contains("P-06") || pierName.Contains("P-07") || pierName.Contains("P-08"))
                        {
                            if (structureName.ToString().Contains("PE"))
                            {
                                structureName = structureName.Substring(0, structureName.Length - 1) + "-" + structureName.Substring(structureName.Length - 1);
                                structureName = structureName + type;
                            }
                            else
                            {
                                if (!structureName.ToString().Contains("PL"))
                                    structureName = structureName + type;
                            }
                            str1 = string.Format("PER COLUMN{0}{1}{2} QUANTITIES FOR {3} OF RAMP BANANI EX-1(COLUMN HEIGHT={4}M)", "\"", structureName, "\"", pierName, pierHeight);
                        }
                        if (pierName.Contains("RP-11") || pierName.Contains("RP-12") || pierName.Contains("RP-13") || pierName.Contains("RP-14")
                            || pierName.Contains("RP-17") || pierName.Contains("RP-18") || pierName.Contains("RP-19") || pierName.Contains("RP-20") || pierName.Contains("RP-21"))
                        {
                            if (structureName.ToString().Contains("PE"))
                            {
                                structureName = structureName.Substring(0, structureName.Length - 1) + "-" + structureName.Substring(structureName.Length - 1);
                                structureName = structureName + type;
                            }
                            str1 = string.Format("PER COLUMN{0}{1}{2} QUANTITIES FOR {3} OF RAMP BANANI EX-2(COLUMN HEIGHT={4}M)", "\"", structureName, "\"", pierName, pierHeight);
                        }
                        //if (pierName.Contains("PR-01") || pierName.Contains("PR-02") || pierName.Contains("PR-03") || pierName.Contains("PR-04") || pierName.Contains("PR-05") || pierName.Contains("PR-06")
                        //  || pierName.Contains("PR-07") || pierName.Contains("PR-08") || pierName.Contains("PR-09") || pierName.Contains("PR-10") || pierName.Contains("PR-11") || pierName.Contains("PR-12"))

                        //{
                        //    str1 = string.Format("PER COLUMN{0}{1}{2} QUANTITIES FOR {3} OF RAMP MOHAKHALI EX-1(COLUMN HEIGHT={4}M)", "\"", structureName, "\"", pierName, pierHeight);
                        //}

                        //string str2 = string.Format("(COLUMN HEIGHT {0})", Common.GetPierHeightDes(typeName, type));
                        TextPloter.PrintScaleDoubleSideText(db, pt.Convert2D(width / 2, 8 * scale), 3, str1, "", ref extMerge, scale, Extensions.curFont);
                    }

                    Common.CreateLayout(db, "基础数据表" + i, ext, extMerge, scale, 1,false, tkPath);
                }
                else
                    Common.CreateLayout(db, "基础数据表" + i, ext, scale, 1,false, tkPath);
            }
            #endregion
        }

        /// <summary>
        /// 墩柱批量绘制
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ret"></param>
        /// <param name="eType"></param>
        /// <param name="dwgPath"></param>
        /// <param name="typeName"></param>
        /// <param name="structureName"></param>
        /// <param name="pierHeight"></param>
        /// <param name="pierName"></param>
        /// <param name="type"></param>
        /// <param name="pageCount"></param>
        /// <param name="pageNo"></param>
        /// <param name="scale"></param>
        /// <param name="title"></param>
        public static void DrawingColumnTableNew(Database db, MemberBase ret, EStructure eType, string dwgPath,
         string typeName, string structureName, string pierHeight, string pierName, FDEE.Model.eSubType type, ref int pageCount, int pageNo = 0, int scale = 1, string title = "MAINLINE", string tkPath = "")
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            _dwgPath = dwgPath;

            Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin.Convert2D(0, -297 * pageNo);
            Point2d M1 = CT.Convert2D(0, -2 * scale);

            #region 分页处理
            List<RebarCollection> divDic = new List<RebarCollection>();
            if (typeName.Contains("PE") || typeName.Contains("PL") || typeName.Contains("PME") || typeName.Contains("PM") || typeName.Contains("PTM1U"))
            {
                CalcCloumPageNew(ret.RebarList, scale, ref divDic);
                //divDic.Add(ret.RebarList);
            }
            else
                CalcCloumPage(ret.RebarList, scale, ref divDic);
            //divDic.Add(ret.RebarList);
            #endregion
            pageCount = divDic.Count;
            #region 绘制表格
            Table lasTb = new Table();
            for (int i = 0; i < divDic.Count; i++)
            {
                ext = new Extents2d(Point2d.Origin.Convert2D(420 * i).Convert2D(0, -297 * pageNo), Point2d.Origin.Convert2D(0, -297 * pageNo));
                lasTb = DrawColumnTable(db, ref ext, M1.Convert3D(), divDic[i].Count + 2,
                    Extensions.curFont, scale, divDic[i], typeName, structureName, pierHeight, pierName, type, i, title);
                Extents2d extMerge = new Extents2d();
                //Common.CreateLayout(db, "基础数据表", ext, extMerge, scale, 1);

                if (i == divDic.Count - 1)
                {
                    // 绘制合并表格
                    RebarCollection listBack = new RebarCollection();
                    listBack = ret.RebarList;
                    List<string> mergeList = new List<string>();
                    mergeList.Add("Materials");
                    mergeList.Add("Materials");
                    mergeList.Add("Unit");
                    mergeList.Add("Weight(kg)");
                    mergeList.Add("Total(kg)");

                    Point3d pt = M1.Convert3D(420 * i + (lasTb.Width - 226) * 0.5, /*-20*/-lasTb.Height - 40 * scale);
                    Table tb = PloterTable.DrawMergeColumnTable(db, ret, eType, ref extMerge, pt, mergeList,
                        Extensions.curFont, scale);
                    double width = 0;
                    double height = 0;
                    if (tb != null)
                    {
                        width = tb.Width;
                        height = tb.Height;

                        string str1 = string.Format("PER COLUMN{0}{1}{2} QUANTITIES FOR {3} OF " + title + "(COLUMN HEIGHT={4}M)", "\"", structureName, "\"", pierName, pierHeight);
                        if (pierName.Contains("P-06") || pierName.Contains("P-07") || pierName.Contains("P-08"))
                        {
                            if (structureName.ToString().Contains("PE"))
                            {
                                structureName = structureName.Substring(0, structureName.Length - 1) + "-" + structureName.Substring(structureName.Length - 1);
                                if (!structureName.ToString().Contains("PL"))
                                    structureName = structureName + type.ToString().Replace("M", "*");
                            }
                            else
                            {
                                if (!structureName.ToString().Contains("PL"))
                                    structureName = structureName + "-" + type.ToString().Replace("M", "*");
                            }
                            str1 = string.Format("PER COLUMN {0}{1}{2} QUANTITIES FOR {3} OF RAMP BANANI EX-1(COLUMN HEIGHT={4}M)", "\"", structureName, "\"", pierName, pierHeight);
                        }
                        if (pierName.Contains("RP11") || pierName.Contains("RP12") || pierName.Contains("RP13") || pierName.Contains("RP14")
                           || pierName.Contains("RP17") || pierName.Contains("RP18") || pierName.Contains("RP19") || pierName.Contains("RP20") || pierName.Contains("RP21"))
                        {
                            if (structureName.ToString().Contains("PE"))
                            {
                                structureName = structureName.Substring(0, structureName.Length - 1) + "-" + structureName.Substring(structureName.Length - 1);
                                if (!structureName.ToString().Contains("PL"))
                                    structureName = structureName + type.ToString().Replace("M", "*");
                            }
                            str1 = string.Format("PER COLUMN {0}{1}{2} QUANTITIES FOR {3} OF RAMP BANANI EX-2(COLUMN HEIGHT={4}M)", "\"", structureName, "\"", pierName, pierHeight);
                        }
                        else
                        {
                            if (structureName.ToString().Contains("PE"))
                            {
                                structureName = structureName.Substring(0, structureName.Length - 1) + "-" + structureName.Substring(structureName.Length - 1);

                                structureName = structureName + type.ToString().Replace("M", "*");
                            }
                            else if (!structureName.ToString().Contains("PL"))
                                structureName = structureName + "-" + type.ToString().Replace("M", "*");
                            str1 = string.Format("PER COLUMN {0}{1}{2} QUANTITIES FOR {3} OF  " + title + "(COLUMN HEIGHT={4}M)", "\"", structureName, "\"", pierName, pierHeight);
                        }
                        //string str2 = string.Format("(COLUMN HEIGHT {0})", Common.GetPierHeightDes(typeName, type));
                        TextPloter.PrintScaleDoubleSideText(db, pt.Convert2D(width / 2, 8 * scale), 3, str1, "", ref extMerge, scale, Extensions.curFont);
                    }

                    Common.CreateLayoutNew(db, "墩柱钢筋", ext, extMerge, scale, 1, pageNo, i,false,tkPath);
                }
                else
                    Common.CreateLayoutNew(db, "墩柱钢筋", ext, scale, 1, pageNo, i,false,tkPath);
            }
            #endregion
        }


        public static void DrawingColumnRebar(Database db, string dwgPath,
string typeName,string pierHeighttype, double scale = 1, string tkPath = "")
        {
            try
            {
                _dwgPath = dwgPath;
                #region 插入钢筋
                List<Extents2d> exts = new List<Extents2d>();
                if (typeName == "CPE12" || typeName.Replace("A", "").Replace("B", "") == "CPE21" || typeName == "CPE22" || typeName == "CPE32"|| typeName == "CPL2")
                {
                    DrawingRampColumnRebar(db, Point3d.Origin.Convert3D(10, 70), typeName, pierHeighttype, 16, ref exts);
                }
                else
                    DrawingMainColumnRebar(db, Point3d.Origin.Convert3D(10, 70),  typeName, pierHeighttype, scale, ref exts);
                if (exts.Count > 0)
                {
                    for (int i = 0; i < exts.Count; i++)
                    {
                        if (typeName == "CPE12" || typeName == "CPE21" || typeName == "CPE22" || typeName == "CPE32"|| typeName == "CPL2")
                        {
                            if(typeName == "CPL2"&&i== exts.Count-1)
                            {
                                Common.CreateLayoutNew(db, "墩柱钢筋", exts[i], 1, 1, -1, i, false, tkPath);
                            }
                            else
                               Common.CreateCRLayoutNew(db, "墩柱钢筋", exts[i], 1, 1, -1, i, false, tkPath);
                            try
                            {
                                _blcName = "R" + typeName.Replace("C", "").Replace("A", "").Replace("B", "") + pierHeighttype;
                                if(typeName == "CPL2")
                                    _blcName = "R" + typeName.Replace("C", "");
                                db.CopyBlockFromFile(_dwgPath, _blcName);
                                BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -1).Convert3D(363.7, 255.6), 1, _blcName, _dwgPath, 0, false);
                            }
                            catch { }
                        }
                        else
                        {
                            if (typeName == "CPTM3U")
                            {
                                if (i == 0)
                                    Common.CreateCRLayoutNew(db, "墩柱钢筋", exts[i], 1, 1, -1, i, false, tkPath);
                                else
                                    Common.CreateLayoutNew(db, "墩柱钢筋", exts[i], 1, 1, -1, i, false, tkPath);
                            }
                            else
                                Common.CreateCRLayoutNew(db, "墩柱钢筋", exts[i], 1, 1, -1, i, false, tkPath);

                            if (i == 0)
                            {
                                try
                                {
                                    _blcName = "R" + typeName.Replace("C", "")+pierHeighttype;
                                    db.CopyBlockFromFile(_dwgPath, _blcName);
                                    if (typeName == "CPTM2S" && pierHeighttype=="B")
                                        BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -1).Convert3D(363.7, 235.6), 1, _blcName, _dwgPath, 0, false);
                                    else if (typeName == "CPTM3S"|| typeName == "CPTM3U" || typeName == "CPTL2"|| typeName == "CPTE3")
                                        BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -1).Convert3D(363.7, 250.6), 1, _blcName, _dwgPath, 0, false);
                                    else if (typeName == "CPTE32")
                                        BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -1).Convert3D(362, 250.6), 1, _blcName, _dwgPath, 0, false);
                                    else
                                        BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -1).Convert3D(363.7, 245.6), 1, _blcName, _dwgPath, 0, false);
                                }
                                catch { }
                            }

                        }
                    }
                }
                #endregion
            }
            catch
            {

            }
        }
        public static void DrawingRampColumnRebar(Database db, Point3d startPoint, string typeName, string pierHeighttype, double scale, ref List<Extents2d> exts)
        {
            if (typeName == "CPE12" || typeName.Replace("A", "").Replace("B", "") == "CPE21" || typeName == "CPE22" || typeName == "CPE32" )
            {
                #region 第一页

                Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
              
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "") + pierHeighttype + "-1";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(), scale, _blcName, _dwgPath, null, null, ref ext);
               
                double width = ext.W() - 10;              
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "") + pierHeighttype + "-2";

                Extents2d ext1 = new Extents2d(startPoint.Convert2D(width), startPoint.Convert2D(width));
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(width, 45), 20, _blcName, _dwgPath, null, null, ref ext1);
                double height = ext1.L()+10;

                _blcName = "MainLap";
                db.CopyBlockFromFile(_dwgPath, _blcName);               
                BlockTool.InsertBlockReference(startPoint.Convert3D(width, height), 1, _blcName, _dwgPath, null, null, ref ext);

                ext = ext.Add(ext1);
                exts.Add(ext);
                #endregion

                #region 第二页
                startPoint = startPoint.Convert3D(420);
                ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                startPoint = startPoint.Convert3D(420);

                ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "") + pierHeighttype + "-31";
                db.CopyBlockFromFile(_dwgPath, _blcName);           
                BlockTool.InsertBlockReference(startPoint.Convert3D(), 25, _blcName, _dwgPath, null, null, ref ext);
                width = ext.W()+5;
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "") + pierHeighttype + "-32";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(width), 25, _blcName, _dwgPath, null, null, ref ext);
                height= ext.L()+2;
               double widthL = ext.W() + 5;

                ext1 = new Extents2d(startPoint.Convert2D(0, height), startPoint.Convert2D(0, height));
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "") + pierHeighttype + "-21";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(0, height), 25, _blcName, _dwgPath, null, null, ref ext1);
                width = ext1.W() + 5;
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "") + pierHeighttype + "-22";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(width, height), 25, _blcName, _dwgPath, null, null, ref ext1);
                height = ext1.L() + 2;
                ext = ext.Add(ext1);
                height = ext.L() + 2;
                double widthM = ext.W() + 5;
                ext1 = new Extents2d(startPoint.Convert2D(0, height), startPoint.Convert2D(0, height));
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "") + pierHeighttype + "-11";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(0, height), 25, _blcName, _dwgPath, null, null, ref ext1);
                width = ext1.W() + 5;
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "") + pierHeighttype + "-12";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(width, height), 25, _blcName, _dwgPath, null, null, ref ext1);
                ext = ext.Add(ext1);

                Extents2d ext2 = new Extents2d(startPoint.Convert2D(widthL, 75), startPoint.Convert2D(widthL, 75));
                string Contents =
              "Notes:\\P" +
              "    1. All dimensions are in m unless otherwise indicated.\\P" +
              "    2. The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer & architect before commencement of work.\\P" +
              "    3. All the produced unsuitable material shall be transport to the designate disposal area in a properly manner. \\P" +
              "    4. All the site activities and operations shall follow the requirement of the approved Health and Safety Managemen Plan strictly.\\P" +
              "    5. Concrete shall have the minimum 35MPa of cylinder compressive strength at 28 days.\\P" +
              "    6. Reinforcement steel shall have the minimum yield strength 500MPa.\\P" +
              "    7. Concrete cover shall be 0.050m for cross beam..";
                TextPloter.PrintMultiText(db, ref ext2, startPoint.Convert3D(widthL, 75), Contents, 1, 2.5, 154);
                //height = ext2.L();
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "") + pierHeighttype + "-42";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(widthM, 80), 25, _blcName, _dwgPath, null, null, ref ext2);
                height = ext2.L()+5;
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "") + pierHeighttype + "-41";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(widthM, 25+ height), 25, _blcName, _dwgPath, null, null, ref ext2);
                ext = ext.Add(ext2);
                exts.Add(ext);
                #endregion
            }
            else if (typeName == "CPL2")
            {
                #region 第一页

                Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());

                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "")  + "-1";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(), scale, _blcName, _dwgPath, null, null, ref ext);

                double width = ext.W() - 10;
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "")  + "-2";

                Extents2d ext1 = new Extents2d(startPoint.Convert2D(width), startPoint.Convert2D(width));
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(width, 45), 20, _blcName, _dwgPath, null, null, ref ext1);
                double height = ext1.L() + 10;

                _blcName = "MainLap";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(width, height), 1, _blcName, _dwgPath, null, null, ref ext);

                ext = ext.Add(ext1);
                exts.Add(ext);
                #endregion

                #region 第二页
                startPoint = startPoint.Convert3D(420);
                ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                startPoint = startPoint.Convert3D(420);

                ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "")  + "-21";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(), 25, _blcName, _dwgPath, null, null, ref ext);
                width = ext.W() + 5;
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "")  + "-22";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(width), 25, _blcName, _dwgPath, null, null, ref ext);
                height = ext.L() + 10;
                double widthL = ext.W() + 5;

                ext1 = new Extents2d(startPoint.Convert2D(0, height), startPoint.Convert2D(0, height));
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "")  + "-11";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(0, height), 25, _blcName, _dwgPath, null, null, ref ext1);
                width = ext1.W() + 5;
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "")  + "-12";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(width, height), 25, _blcName, _dwgPath, null, null, ref ext1);
                height = ext1.L() + 2;
                ext = ext.Add(ext1);
        
                double widthM = ext.W() + 5;

                ext1 = new Extents2d(startPoint.Convert2D(widthM, 55), startPoint.Convert2D(widthM, 55));
                string Contents =
        "Notes:\\P" +
        "    1. All dimensions are in m unless otherwise indicated.\\P" +
        "    2. The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer & architect before commencement of work.\\P" +
        "    3. All the produced unsuitable material shall be transport to the designate disposal area in a properly manner. \\P" +
        "    4. All the site activities and operations shall follow the requirement of the approved Health and Safety Managemen Plan strictly.\\P" +
        "    5. Concrete shall have the minimum 35MPa of cylinder compressive strength at 28 days.\\P" +
        "    6. Reinforcement steel shall have the minimum yield strength 500MPa.\\P" +
        "    7. Concrete cover shall be 0.050m for cross beam..";
                TextPloter.PrintMultiText(db, ref ext1, startPoint.Convert3D(widthM, 55), Contents, 1, 2.5, 154);
                //ext1 = new Extents2d(startPoint.Convert2D(0, height), startPoint.Convert2D(0, height));
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "")  + "-32";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(widthM, 47), 25, _blcName, _dwgPath, null, null, ref ext1);
                height = ext1.L() + 2;
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "")  + "-31";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(widthM, 10+height), 25, _blcName, _dwgPath, null, null, ref ext1);
                ext = ext.Add(ext1);
                exts.Add(ext);
                #endregion

                #region 第三页
                startPoint = startPoint.Convert3D(420);
                Extents2d ext2 = new Extents2d(startPoint.Convert2D(0, 100), startPoint.Convert2D(0, 100));
       
                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "")  + "-41";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(0, 100), 25, _blcName, _dwgPath, null, null, ref ext2);
                width = ext2.W() + 5;

                _blcName = typeName.Replace("C", "").Replace("A", "").Replace("B", "")  + "-42";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(width, 100), 25, _blcName, _dwgPath, null, null, ref ext2);
              
                TextPloter.PrintMultiText(db, ref ext2, startPoint.Convert3D(10, 95), Contents, 1, 2.5, 200);
                exts.Add(ext2);
                #endregion
            }
        }

        public static void DrawingMainColumnRebar(Database db, Point3d startPoint,  string typeName, string pierHeighttype, double scale, ref List<Extents2d> exts)
        {
          
            if (typeName == "CPTM1" || typeName == "CPTM1S" || typeName == "CPTM2" || typeName == "CPTM2S" || typeName == "CPTM3S" || typeName == "CPTM3U" || typeName == "CPTE3" || typeName == "CPTE32" || typeName == "CPTL2")
            {
                #region 第一页
               
                Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                if (typeName == "CPTM3U")
                    startPoint = startPoint.Convert3D(15);
                _blcName = typeName.Replace("C", "") + pierHeighttype + "-1";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(), scale, _blcName, _dwgPath, null, null, ref ext);
              
                double width = ext.W() + 5;
                if (typeName == "CPTM3S")
                    width = ext.W();
                _blcName = typeName.Replace("C", "") + pierHeighttype + "-2";

                Extents2d ext1 = new Extents2d(startPoint.Convert2D(width), startPoint.Convert2D(width));
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(width, -10), 20, _blcName, _dwgPath, null, null, ref ext1);
                double height = ext1.L() + 5;
             
                _blcName = "MainLap";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                if(typeName == "CPTM1S"||typeName=="CPTM2S")
                    BlockTool.InsertBlockReference(startPoint.Convert3D(width-15, height-10), 1, _blcName, _dwgPath, null, null, ref ext);

                else
                    BlockTool.InsertBlockReference(startPoint.Convert3D(width, height), 1, _blcName, _dwgPath, null, null, ref ext);
              
                string Contents =
              "Notes:\\P" +
              "    1. All dimensions are in m unless otherwise indicated.\\P" +
              "    2. The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer & architect before commencement of work.\\P" +
              "    3. All the produced unsuitable material shall be transport to the designate disposal area in a properly manner. \\P" +
              "    4. All the site activities and operations shall follow the requirement of the approved Health and Safety Managemen Plan strictly.\\P" +
              "    5. Concrete shall have the minimum 35MPa of cylinder compressive strength at 28 days.\\P" +
              "    6. Reinforcement steel shall have the minimum yield strength 500MPa.\\P" +
              "    7. Concrete cover shall be 0.050m for cross beam..";
                TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(15, 15), Contents, 1, 2.5, 250);
                ext = ext.Add(ext1);
                exts.Add(ext);
                #endregion

                #region 第二页
                startPoint = startPoint.Convert3D(420);
              
                ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                _blcName = typeName.Replace("C", "") + pierHeighttype + "-S";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                if(typeName == "CPTM3U")
                    BlockTool.InsertBlockReference(startPoint.Convert3D(), 25, _blcName, _dwgPath, null, null, ref ext);
                else
                  BlockTool.InsertBlockReference(startPoint.Convert3D(), 40, _blcName, _dwgPath, null, null, ref ext);
               
                exts.Add(ext);
                #endregion

                #region 第三页
                if (typeName != "CPTL2")
                {
                    startPoint = startPoint.Convert3D(420);
                    ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                    _blcName = typeName.Replace("C", "") + pierHeighttype + "-T";
                    db.CopyBlockFromFile(_dwgPath, _blcName);
                    if (typeName == "CPTM3U")
                        BlockTool.InsertBlockReference(startPoint.Convert3D(), 25, _blcName, _dwgPath, null, null, ref ext);
                    else
                        BlockTool.InsertBlockReference(startPoint.Convert3D(0, 0), 40, _blcName, _dwgPath, null, null, ref ext);


                    exts.Add(ext);
                }
                #endregion
            }

        }

        #endregion

     

        #region 废弃
        /// <summary>
        /// 盖梁
        /// </summary>
        /// <param name="db"></param>
        /// <param name="eType"></param>
        /// <param name="listRebar"></param>
        /// <param name="dwgPath"></param>
        /// <param name="typeName"></param>
        /// <param name="structureName"></param>
        /// <param name="type"></param>
        /// <param name="eConType"></param>
        /// <param name="conValue"></param>
        /// <param name="scale"></param>
        public static void DrawingCapBeamTable(Database db, MemberBase ret, EStructure eType, string dwgPath,
            string typeName, string structureName, string pierName, string capLength, FDEE.Model.eSubType type, int scale = 1)
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("表格数据为空");
            }
            _dwgPath = dwgPath;
            structureName = ret.TypeName;
            #region 测试数据
            #endregion

            Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin;
            Point2d M1 = CT.Convert2D(0, -2 * scale);

            #region 分页处理
            List<RebarCollection> divDic = new List<RebarCollection>();
            CalcBeamPage(ret.RebarList, scale, ref divDic);
            #endregion

            #region 绘制表格
            Table lasTb = new Table();
            for (int i = 0; i < divDic.Count; i++)
            {
                ext = ext = new Extents2d(Point2d.Origin.Convert2D(420 * i), Point2d.Origin);
                lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(), divDic[i].Count + 2,
                    Extensions.curFont, scale, divDic[i], typeName, structureName, capLength, "", type, i);
                Extents2d extMerge = new Extents2d();


                if (i == divDic.Count - 1)
                {
                    // 绘制合并表格
                    RebarCollection listBack = new RebarCollection();
                    listBack = ret.RebarList;
                    List<string> mergeList = new List<string>();
                    mergeList.Add("Materials");
                    mergeList.Add("Materials");
                    mergeList.Add("Unit");
                    mergeList.Add("Weight(kg)");
                    mergeList.Add("Total(kg)");

                    Point3d pt = M1.Convert3D(/*420 * divDic.Count*/0, /*-20*/-lasTb.Height - 400 * scale);
                    Table tb = PloterTable.DrawMergeBeamTable(db, ret, eType, ref extMerge, pt, mergeList,
                        Extensions.curFont, scale);
                    double width = 0;
                    double height = 0;
                    if (tb != null)
                    {
                        width = tb.Width;
                        height = tb.Height;

                        string str1 = string.Format("QUANTITIES OF TYPICAL CROSS BEAM FOR '{0}' OF MAINLINE", pierName);
                        string str2 = "";
                        TextPloter.PrintScaleDoubleSideText(db, pt.Convert2D(width / 2, 8 * scale), 3, str1, str2, ref extMerge, scale, Extensions.curFont);
                    }

                    Common.CreateLayout(db, "基础数据表" + i, ext, extMerge, scale, 1);
                }
                else
                {

                    Common.CreateLayout(db, "基础数据表" + i, ext, scale, 1);
                }
            }
            #endregion

            #region 创建布局、视口

            #endregion
        }

        public static void DrawingCapBeamTableNew(Database db, MemberBase ret, EStructure eType, string dwgPath,
          string typeName, string structureName, string pierName, string capLength, FDEE.Model.eSubType type, int scale = 1,string tkPath="")
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("表格数据为空");
            }
            _dwgPath = dwgPath;
            structureName = ret.TypeName;
            #region 测试数据
            #endregion

            Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin;
            Point2d M1 = CT.Convert2D(0, -2 * scale);

            #region 分页处理
            List<RebarCollection> divDic = new List<RebarCollection>();
            CalcBeamPage(ret.RebarList, scale, ref divDic);
            #endregion

            #region 绘制表格
            Table lasTb = new Table();
            for (int i = 0; i < divDic.Count; i++)
            {
                ext = ext = new Extents2d(Point2d.Origin.Convert2D(420 * i), Point2d.Origin);
                lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(), divDic[i].Count + 2,
                    Extensions.curFont, scale, divDic[i], typeName, structureName, capLength, "", type, i);
                Extents2d extMerge = new Extents2d();


                if (i == divDic.Count - 1)
                {
                    // 绘制合并表格
                    RebarCollection listBack = new RebarCollection();
                    listBack = ret.RebarList;
                    List<string> mergeList = new List<string>();
                    mergeList.Add("Materials");
                    mergeList.Add("Materials");
                    mergeList.Add("Unit");
                    mergeList.Add("Weight(kg)");
                    mergeList.Add("Total(kg)");

                    Point3d pt = M1.Convert3D(/*420 * divDic.Count*/0, /*-20*/-lasTb.Height - 400 * scale);
                    Table tb = PloterTable.DrawMergeBeamTable(db, ret, eType, ref extMerge, pt, mergeList,
                        Extensions.curFont, scale);
                    double width = 0;
                    double height = 0;
                    if (tb != null)
                    {
                        width = tb.Width;
                        height = tb.Height;

                        string str1 = string.Format("QUANTITIES OF TYPICAL CROSS BEAM FOR '{0}' OF MAINLINE", pierName);
                        string str2 = "";
                        TextPloter.PrintScaleDoubleSideText(db, pt.Convert2D(width / 2, 8 * scale), 3, str1, str2, ref extMerge, scale, Extensions.curFont);
                    }

                    Common.CreateLayout(db, "基础数据表" + i, ext, extMerge, scale, 1,false, tkPath);
                }
                else
                {

                    Common.CreateLayout(db, "基础数据表" + i, ext, scale, 1,false, tkPath);
                }
            }
            #endregion

            #region 创建布局、视口

            #endregion
        }
        #endregion

        #region 盖梁
        /// <summary>
        /// 绘制盖梁钢筋
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ret"></param>
        /// <param name="eType"></param>
        /// <param name="dwgPath"></param>
        /// <param name="typeName"></param>
        /// <param name="structureName"></param>
        /// <param name="capLength"></param>
        /// <param name="pierName"></param>
        /// <param name="type"></param>
        /// <param name="pageCount"></param>
        /// <param name="pageNo"></param>
        /// <param name="scale"></param>
        /// <param name="title"></param>
        public static void DrawingCapBeamTableNew(Database db, MemberBase ret, EStructure eType, string dwgPath,
    string typeName, string structureName, string capLength, string pierName, FDEE.Model.eSubType type, ref int pageCount, int pageNo = 0, int scale = 1, string title = "MAINLINE",string tkPath="")
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            _dwgPath = dwgPath;

            Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin.Convert2D(0, -297 * pageNo);
            Point2d M1 = CT.Convert2D(0, -2 * scale);

            #region 分页处理
            List<RebarCollection> divDic = new List<RebarCollection>();
            if (typeName.Contains("PE") || typeName.Contains("PL"))
            {
                CalcBeamPage(ret.RebarList, scale, ref divDic);
            }
            else
                CalcBeamPage(ret.RebarList, scale, ref divDic);
            #endregion
            pageCount = divDic.Count;
         
            #region 绘制表格
            Table lasTb = new Table();
            for (int i = 0; i < divDic.Count; i++)
            {
                ext = new Extents2d(Point2d.Origin.Convert2D(420 * i).Convert2D(0, -297 * pageNo), Point2d.Origin.Convert2D(0, -297 * pageNo));
                lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(), divDic[i].Count + 2,
                 Extensions.curFont, scale, divDic[i], typeName, structureName, capLength, "", type, i);
                //lasTb = DrawColumnTable(db, ref ext, M1.Convert3D(), divDic[i].Count + 2,
                //    Extensions.curFont, scale, divDic[i], typeName, structureName, pierHeight, pierName, type, i, title);
                Extents2d extMerge = new Extents2d();
                //Common.CreateLayout(db, "基础数据表", ext, extMerge, scale, 1);

                if (i == divDic.Count - 1)
                {
                    // 绘制合并表格
                    RebarCollection listBack = new RebarCollection();
                    listBack = ret.RebarList;
                    List<string> mergeList = new List<string>();
                    mergeList.Add("Materials");
                    mergeList.Add("Materials");
                    mergeList.Add("Unit");
                    mergeList.Add("Weight(kg)");
                    mergeList.Add("Total(kg)");

                    Point3d pt = M1.Convert3D(420 * i + (lasTb.Width - 226) * 0.5, /*-20*/-lasTb.Height - 40 * scale);
                    Table tb = PloterTable.DrawMergeBeamTable(db, ret, eType, ref extMerge, pt, mergeList,
                      Extensions.curFont, scale);
                    double width = 0;
                    double height = 0;
                    if (tb != null)
                    {
                        width = tb.Width;
                        height = tb.Height;
                        string str1 = string.Format("QUANTITIES OF TYPICAL CROSS BEAM FOR '{0}' OF {1}", pierName, title);
                        string str2 = "";
                        TextPloter.PrintScaleDoubleSideText(db, pt.Convert2D(width / 2, 8 * scale), 3, str1, str2, ref extMerge, scale, Extensions.curFont);
                    }

                    Common.CreateLayoutNew(db, "盖梁钢筋数据表", ext, extMerge, scale, 1, pageNo, i,false, tkPath);
                }
                else
                    Common.CreateLayoutNew(db, "盖梁钢筋数据表", ext, scale, 1, pageNo, i,false, tkPath);
            }
            #endregion
        }

        public static void DrawingCapBeamRebarNew(Database db,  string dwgPath, double length,
 string typeName,  double scale = 1, string tkPath = "",string columnNo="")
        {
            try
            {
                _dwgPath = dwgPath;
                string directoryName = System.IO.Path.GetDirectoryName(_dwgPath);
                string reberBlockPath = directoryName + @"\BeamReberBlock.dwg";//构造物
                #region 插入钢筋
                List<Extents2d> exts = new List<Extents2d>();
                if (typeName == "BPE12" || typeName == "BPE21" || typeName == "BPE22" || typeName == "BPE32")
                    DrawingCapBeamRebar(db, Point3d.Origin.Convert3D(420 * 0.4, 297), length, typeName, scale, ref exts);
                else
                {
                    if (typeName == "BPTM1" || typeName == "BPTM1S" || typeName == "BPTM2" || typeName == "BPTM2S" || typeName == "BPTM3S")
                        DrawingMainCapBeamRebar(db, Point3d.Origin.Convert3D(420 * 0.4, 297 * 3), length, typeName, scale, ref exts, columnNo);
                    else
                        DrawingMainCapBeamRebar(db, Point3d.Origin.Convert3D(420 * 0.4, 297), length, typeName, scale, ref exts, columnNo);
                }
                if (exts.Count > 0)
                {
                    for (int i = 0; i < exts.Count; i++)
                    {
                        if (typeName == "BPE21" || typeName == "BPE22" || typeName == "BPE32")
                        {
                            Common.CreateLayoutNew(db, "盖梁钢筋数据表", exts[i], 1, 1, -1, i, false, tkPath);
                            _blcName = "R" + typeName.Replace("B", "");
                            db.CopyBlockFromFile(reberBlockPath, _blcName);
                            BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -1).Convert3D(360.4, 253.26), 1, _blcName, reberBlockPath, 0, false);
                        }
                        else if (typeName == "BPE12")
                        {
                            Common.CreateRebarLayoutNew(db, "盖梁钢筋数据表", exts[i], 1, 1, -1, i, false, tkPath);
                            _blcName = "R" + typeName.Replace("B", "");
                            db.CopyBlockFromFile(reberBlockPath, _blcName);
                            BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -1).Convert3D(360.4, 253.26), 1, _blcName, reberBlockPath, 0, false);
                        }
                        else
                        {
                            if (typeName == "BPTM1" || typeName == "BPTM1S" || typeName == "BPTM2" || typeName == "BPTM2S" || typeName == "BPTM3S")
                            {
                                if (i < exts.Count - 1)
                                    Common.CreateRLayoutNew(db, "盖梁钢筋数据表", exts[i], 1, 1, -3, i, false, tkPath);
                                else
                                    Common.CreateBeamPLayoutNew(db, "盖梁钢筋数据表", exts[i], 1, 1, -3, i, false, tkPath);

                                _blcName = "R" + typeName.Replace("B", "");
                                db.CopyBlockFromFile(reberBlockPath, _blcName);

                                if (typeName == "BPTM3S")
                                    BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -3).Convert3D(355.26, 238.6), 1, _blcName, reberBlockPath, 0, false);
                                else if (typeName == "BPTE3")
                                    BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -3).Convert3D(355.26, 249.1), 1, _blcName, reberBlockPath, 0, false);
                                else
                                    BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -3).Convert3D(355.26, 244), 1, _blcName, reberBlockPath, 0, false);
                            }
                            else
                            {
                                if (i < exts.Count - 1)
                                    Common.CreateRLayoutNew(db, "盖梁钢筋数据表", exts[i], 1, 1, -1, i, false, tkPath);
                                else
                                    Common.CreateBeamPLayoutNew(db, "盖梁钢筋数据表", exts[i], 1, 1, -1, i, false, tkPath);

                                _blcName = "R" + typeName.Replace("B", "");
                                db.CopyBlockFromFile(reberBlockPath, _blcName);

                                if (typeName == "BPTM3S")
                                    BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -1).Convert3D(355.26, 238.6), 1, _blcName, reberBlockPath, 0, false);
                                else if (typeName == "BPTE3")
                                    BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -1).Convert3D(355.26, 249.1), 1, _blcName, reberBlockPath, 0, false);
                                else
                                    BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -1).Convert3D(355.26, 244), 1, _blcName, reberBlockPath, 0, false);
                            }

                           

                        }
                    }
                }
                #endregion
            }
            catch
            {

            }
        }

        public static void DrawingCapBeamRebar(Database db, Point3d startPoint,double length, string typeName, double scale, ref List<Extents2d> exts)
        {
            string directoryName = System.IO.Path.GetDirectoryName(_dwgPath);
            string  reberBlockPath = directoryName + @"\BeamReberBlock.dwg";//构造物
            Dictionary<string, Dictionary<string, string>> dicA = new Dictionary<string, Dictionary<string, string>>();
            Dictionary<string, string> dicT = new Dictionary<string, string>();
            if (typeName == "BPE12" || typeName == "BPE21" || typeName == "BPE22" || typeName == "BPE32")
            {
                dicA = new Dictionary<string, Dictionary<string, string>>();
                dicT = new Dictionary<string, string>();
                dicT.Add(length.ToString("0.000"), "string");
                dicA.Add("LENGTH", dicT);
                Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                _blcName = typeName.Replace("B", "") + "-1";
                db.CopyBlockFromFile(reberBlockPath, _blcName);
                //BlockTool.InsertBlockReference(startPoint.Convert3D(), scale, _blcName, _dwgPath,ref ext);
                BlockTool.InsertBlockReference(startPoint.Convert3D(), scale, _blcName, reberBlockPath, dicA, null, ref ext);
                double height = ext.L()-20;
                if (typeName == "BPE21")
                    height = ext.L() -50;
                else if (typeName == "BPE22" || typeName == "BPE32")
                    height = ext.L()+10;
                //ext = new Extents2d(startPoint.Convert2D(0,- height), startPoint.Convert2D(0, -height));
                _blcName = typeName.Replace("B", "") + "-2";
                db.CopyBlockFromFile(reberBlockPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(0, -height), scale, _blcName, reberBlockPath, dicA, null, ref ext);

                Extents2d ext1 = new Extents2d(startPoint.Convert2D(0, -height), startPoint.Convert2D(0, -height));
                _blcName = typeName.Replace("B", "") + "-4";
                db.CopyBlockFromFile(reberBlockPath, _blcName);
                if (typeName == "BPE22" || typeName == "BPE32")
                    BlockTool.InsertBlockReference(startPoint.Convert3D(ext.W() * 0.5 + 45, -height + 10), scale+25, _blcName, _dwgPath, dicA, null, ref ext);
                else
                    BlockTool.InsertBlockReference(startPoint.Convert3D(ext.W() * 0.5 + 10, -height), scale+20, _blcName, reberBlockPath, null, null, ref ext1);
                //BlockTool.InsertBlockReference(startPoint.Convert3D(ext.W()*0.5+10, -height), scale, _blcName, _dwgPath, ref ext1);
             

                height = ext.L()-20;
                if (typeName == "BPE21")
                    height = ext.L() - 60;
                else if (typeName == "BPE22" || typeName == "BPE32")
                    height = ext.L()+10;
                //ext = new Extents2d(startPoint.Convert2D(0, -height), startPoint.Convert2D(0, -height));
                _blcName = typeName.Replace("B", "") + "-3";
                db.CopyBlockFromFile(_dwgPath, _blcName);
                //BlockTool.InsertBlockReference(startPoint.Convert3D(0, -height), scale, _blcName, _dwgPath, ref ext);
          
                BlockTool.InsertBlockReference(startPoint.Convert3D(0, -height), scale, _blcName, _dwgPath, dicA, null, ref ext);
                string Contents =
              "Notes:\\P" +
              "    1. All dimensions are in m unless otherwise indicated.\\P" +
              "    2. The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer & architect before commencement of work.\\P" +
              "    3. All the produced unsuitable material shall be transport to the designate disposal area in a properly manner. \\P" +
              "    4. All the site activities and operations shall follow the requirement of the approved Health and Safety Managemen Plan strictly.\\P" +
              "    5. Concrete shall have the minimum 45MPa of cylinder compressive strength at 28 days.\\P" +
              "    6. Reinforcement steel shall have the minimum yield strength 500MPa.\\P" +
              "    7. Concrete cover shall be 0.050m for cross beam.";
                TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(ext.W()*0.5-25 , -height+20), Contents, 1, 2.5, 100);
                ext.Add(ext1);
                exts.Add(ext);              
            }

        }

        public static void DrawingMainCapBeamRebar(Database db, Point3d startPoint, double length, string typeName, double scale, ref List<Extents2d> exts, string columnNo = "")
        {
            Dictionary<string, Dictionary<string, string>> dicA = new Dictionary<string, Dictionary<string, string>>();
            Dictionary<string, string> dicT = new Dictionary<string, string>();
            string directoryName = System.IO.Path.GetDirectoryName(_dwgPath);
            string reberBlockPath = directoryName + @"\BeamReberBlock.dwg";//构造物
            if (typeName == "BPTM1" || typeName == "BPTM1S" || typeName == "BPTM2"|| typeName == "BPTM2S" || typeName == "BPTM3S"||typeName=="BPTE3")
            {
                #region 第一页
                dicA = new Dictionary<string, Dictionary<string, string>>();
                dicT = new Dictionary<string, string>();
                dicT.Add(((length-2*0.8 )* 0.5).ToString("0.000"), "string");
                dicA.Add("LEFTWIDTH", dicT);
                if (typeName == "BPTM3S")
                {
                    dicT = new Dictionary<string, string>();
                    dicT.Add((length).ToString("0.000"), "string");
                    dicA.Add("TWIDTH", dicT);
                }
                else
                {
                    dicT = new Dictionary<string, string>();
                    dicT.Add((length - 2 * 0.8).ToString("0.000"), "string");
                    dicA.Add("TWIDTH", dicT);
                }
                dicT = new Dictionary<string, string>();
                dicT.Add(((length - 2 * 0.8) * 0.5).ToString("0.000"), "string");
                dicA.Add("RIGHTWIDTH", dicT);
                Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                _blcName = typeName.Replace("B", "") + "-T1";
                db.CopyBlockFromFile(reberBlockPath, _blcName);             
                BlockTool.InsertBlockReference(startPoint.Convert3D(), scale, _blcName, reberBlockPath, dicA, null, ref ext);
                //double height = ext.L() -10;
                //if (typeName == "BPTM1" || typeName == "BPTM1S" || typeName == "BPTM3S" ||  typeName == "BPTE3")
                //{
                double height = ext.L() + 5;
                //}
                _blcName = typeName.Replace("B", "") + "-T2";
                dicA = new Dictionary<string, Dictionary<string, string>>();
                if (typeName == "BPTM1"|| typeName == "BPTM1S")
                {                  
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 7) * 0.5).ToString("0.000"), "string");
                    dicA.Add("LEFTWIDTH", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 7) * 0.5).ToString("0.000"), "string");
                    dicA.Add("RIGHTWIDTH", dicT);
                }
                else if (typeName == "BPTM2")
                {
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 5.3) * 0.5).ToString("0.000"), "string");
                    dicA.Add("LEFTWIDTH", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 5.3) * 0.5).ToString("0.000"), "string");
                    dicA.Add("RIGHTWIDTH", dicT);
                }
                else if (typeName == "BPTM3S")
                {
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 0.8 - 2 * 2.205) * 0.5).ToString("0.000"), "string");
                    dicA.Add("LEFTWIDTH", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 0.8-2*2.205) * 0.5).ToString("0.000"), "string");
                    dicA.Add("RIGHTWIDTH", dicT);
                }
                else if (typeName == "BPTM2S")
                {
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 4.28) * 0.5).ToString("0.000"), "string");
                    dicA.Add("LEFTWIDTH", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 4.28) * 0.5).ToString("0.000"), "string");
                    dicA.Add("RIGHTWIDTH", dicT);
                }
                else if (typeName == "BPTE3")
                {
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 3.65) * 0.5).ToString("0.000"), "string");
                    dicA.Add("LEFTWIDTH", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 3.65) * 0.5).ToString("0.000"), "string");
                    dicA.Add("RIGHTWIDTH", dicT);
                }

                int quan = 0;
                // int quan = (int)Math.Round(length*1000 / 150, MidpointRounding.AwayFromZero) + 1;
                //N5 = "5 - "+ quan + "-DB25 @0.150";
                //if (typeName == "BPTM2")
                //{
                //    int N51 = 22;
                //    int N52 = 10;
                //    int N53 = 10;
                //    int N54 = 8;
                //    int N55 = 8;
                //    N5 = "5 - " + (quan- N51- N52- N53- N54- N55) + "-DB25 @0.150";
                //}
                //N5 = "5 - " + quan + "-DB25 @0.150";
                //N6 = "6 - " + quan + "-DB16 @0.150";

                string N7 = "";
                if (typeName == "BPTM2S" || typeName == "BPTM2" || typeName == "BPTM3S")
                    quan = (int)(Math.Round(length * 1000 / 600, MidpointRounding.AwayFromZero) + 1) * 3;
                else
                {
                    if (typeName == "BPTE3")
                        quan = (int)(Math.Round(length * 1000 / 600, MidpointRounding.AwayFromZero)) * 2;
                    else
                        quan = (int)(Math.Round(length * 1000 / 600, MidpointRounding.AwayFromZero) + 1) * 2;
                }    
                N7 = "7 -" + quan + "-DB16 @0.300";

                string N5 = "";
                string N6 = "";
                string N91 = "";
                string N92 = "";
                if (typeName == "BPTM1" || typeName == "BPTM1S" || typeName == "BPTM2S" || typeName == "BPTE3")
                {
                    quan = (int)Math.Round(length * 1000 / 150, MidpointRounding.AwayFromZero) + 1;

                    if (typeName == "BPTM1S")
                    {
                        N5 = "5 -" + (quan - 46 * 2) + "-DB25 @0.150";
                        N6 = "6 -" + (quan - 46 * 2) + "-DB16 @0.150";
                        quan = 69 * 2 + (int)Math.Round((length * 1000 - 7000 * 2) / 250, MidpointRounding.AwayFromZero) + 1;
                        N91 = "9.1 -" + (quan - 69 * 2) + "-DB16 @0.250 STIR";
                        N92 = "9.2 -" + (quan - 69 * 2) + "-DB16 @0.250 STIR";
                    }

                    else if (typeName == "BPTM1")
                    {
                        N5 = "5 -" + (quan - 46 * 2) + "-DB25 @0.150";
                        N6 = "6 -" + (quan - 46 * 2) + "-DB16 @0.150";
                        quan = 69 * 2 + (int)Math.Round((length * 1000 - 7000 * 2) / 150, MidpointRounding.AwayFromZero) + 1;
                        N91 = "9.1 -" + (quan - 69 * 2) + "-DB16 @0.150 STIR";
                        N92 = "9.2 -" + (quan - 69 * 2) + "-DB16 @0.150 STIR";
                    }
                   
                    else if (typeName == "BPTM2S")
                    {
                        N5 = "5 -" + (quan - 28 * 2) + "-DB25 @0.150";
                        N6 = "6 -" + (quan - 28 * 2) + "-DB16 @0.150";
                        quan = (int)Math.Round((4280 - 50) / 100.0, MidpointRounding.AwayFromZero) * 2 + (int)Math.Round((length * 1000 - 4280 * 2) / 150, MidpointRounding.AwayFromZero);
                        N91 = "9.1 -" + (quan - 42 * 2) + "-DB16 @0.150 STIR";
                        N92 = "9.2 -" + (quan - 42 * 2) + "-DB16 @0.150 STIR";
                    }
                    else if (typeName == "BPTE3")
                    {
                        quan = (int)Math.Round(length * 1000 / 150, MidpointRounding.AwayFromZero);
                        N5 = "5 -" + (quan - 24 * 2) + "-DB25 @0.150";
                        N6 = "6 -" + (quan - 24 * 2) + "-DB16 @0.150";
                        quan = (int)Math.Round((3650 - 50) / 150.0, MidpointRounding.AwayFromZero) * 2 + (int)Math.Round((length * 1000 - 3650 * 2) / 250, MidpointRounding.AwayFromZero);
                        N91 = "9.1 -" + (quan - 24 * 2) + "-DB16 @0.250 STIR";
                        N92 = "9.2 -" + (quan - 24 * 2) + "-DB16 @0.250 STIR";
                    }
                    dicT = new Dictionary<string, string>();
                    dicT.Add(N5, "string");
                    dicA.Add("N5", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(N6, "string");
                    dicA.Add("N6", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(N7, "string");
                    dicA.Add("N7", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(N91, "string");
                    dicA.Add("N91", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(N92, "string");
                    dicA.Add("N92", dicT);
                }
                else if (typeName == "BPTM3S")
                {
                    dicT = new Dictionary<string, string>();
                    dicT.Add((length).ToString("0.000"), "string");
                    dicA.Add("TWIDTH", dicT);
                }
                else if (typeName == "BPTM2")
                {
                    #region 废弃
                    //quan = (int)Math.Round(length * 1000 / 150, MidpointRounding.AwayFromZero) + 1;
                    //int N51 = 22;
                    //int N52 = 10;
                    //int N53 = 10;
                    //int N54 = 8;
                    //int N55 = 8;
                    //N5 = "5 -" + (quan - N51 - N52 - N53 - N54 - N55-35*2) + "-DB25 @0.150";
                    //int N92A = 34;
                    //int N92B = 40;
                    //if (columnNo == "P-216")
                    //{
                    //    N92A = 33;
                    //    N92B = 40;
                    //}
                    //else if (columnNo == "P-217")
                    //{
                    //    N92A = 32;
                    //    N92B = 37;
                    //}
                  
                    //var LSide = 5300;// 两侧加密长度

                    //quan = 52 * 2 + (int)Math.Round((length * 1000 - LSide * 2) / 250, MidpointRounding.AwayFromZero) + 1;
                    //N91 = "9.1 -" + (quan - 52 * 2) + "-DB16 @0.250 STIR";
                    //if (quan - 52 * 2 - N92A - N92B > 0)
                    //{
                    //    _blcName = typeName.Replace("B", "") + "-T22";
                    //    N92 = "9.2 -" + (quan - 52 * 2 - N92A - N92B) + "-DB16 @0.250 STIR";
                    //    dicT = new Dictionary<string, string>();
                    //    dicT.Add(N92, "string");
                    //    dicA.Add("N92", dicT);
                    //}
                    //else
                    //{
                    //    _blcName = typeName.Replace("B", "") + "-T21";
                    //    N92B = quan - 52 * 2 - N92A;
                    //}
                    //string N92AT = "9.2A -" + N92A+ "-DB16 @0.250 STIR";
                    //string N92BT = "9.2B -" + N92B + "-DB16 @0.250 STIR";
                    //dicT = new Dictionary<string, string>();
                    //dicT.Add(N92, "string");
                    //dicA.Add("N92", dicT);
                    //dicT = new Dictionary<string, string>();
                    //dicT.Add(N5, "string");
                    //dicA.Add("N5", dicT);
                    //dicT = new Dictionary<string, string>();
                    //dicT.Add(N6, "string");
                    //dicA.Add("N6", dicT);
                    //dicT = new Dictionary<string, string>();
                    //dicT.Add(N7, "string");
                    //dicA.Add("N7", dicT);
                    //dicT = new Dictionary<string, string>();
                    //dicT.Add(N91, "string");
                    //dicA.Add("N91", dicT);
                    //dicT = new Dictionary<string, string>();
                    //dicT.Add(N92AT, "string");
                    //dicA.Add("N92A", dicT);
                    //dicT = new Dictionary<string, string>();
                    //dicT.Add(N92BT, "string");
                    //dicA.Add("N92B", dicT);
                    #endregion
                    quan = (int)Math.Round(length * 1000 / 150, MidpointRounding.AwayFromZero) + 1;
                   
                    N5 = "5 -" + (quan) + "-DB25 @0.150";
                    //int N92A = 34;
                    //int N92B = 40;
                    //if (columnNo == "P-216")
                    //{
                    //    N92A = 33;
                    //    N92B = 40;
                    //}
                    //else if (columnNo == "P-217")
                    //{
                    //    N92A = 32;
                    //    N92B = 37;
                    //}

                    var LSide = 5300;// 两侧加密长度

                    quan = 52 * 2 + (int)Math.Round((length * 1000 - LSide * 2) / 250, MidpointRounding.AwayFromZero) + 1;
                    N91 = "9.1 -" + (quan - 52 * 2) + "-DB16 @0.250 STIR";
                    if (quan - 52 * 2 > 0)
                    {
                        _blcName = typeName.Replace("B", "") + "-T2";
                        N92 = "9.2 -" + (quan - 52 * 2 ) + "-DB16 @0.250 STIR";
                        //dicT = new Dictionary<string, string>();
                        //dicT.Add(N92, "string");
                        //dicA.Add("N92", dicT);
                    }
                    //else
                    //{
                    //    _blcName = typeName.Replace("B", "") + "-T21";
                    //    N92B = quan - 52 * 2 - N92A;
                    //}
                    //string N92AT = "9.2A -" + N92A + "-DB16 @0.250 STIR";
                    //string N92BT = "9.2B -" + N92B + "-DB16 @0.250 STIR";
                    dicT = new Dictionary<string, string>();
                    dicT.Add(N92, "string");
                    dicA.Add("N92", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(N5, "string");
                    dicA.Add("N5", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(N6, "string");
                    dicA.Add("N6", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(N7, "string");
                    dicA.Add("N7", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(N91, "string");
                    dicA.Add("N91", dicT);
                    //dicT = new Dictionary<string, string>();
                    //dicT.Add(N92AT, "string");
                    //dicA.Add("N92A", dicT);
                    //dicT = new Dictionary<string, string>();
                    //dicT.Add(N92BT, "string");
                    //dicA.Add("N92B", dicT);
                }

                db.CopyBlockFromFile(reberBlockPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(0, -height), scale, _blcName, reberBlockPath, dicA, null, ref ext);
                if (typeName == "BPTM1" || typeName == "BPTM1S"||typeName == "BPTM2" )
                {
                    height = ext.L() - 15;
                }
                else
                {
                    height = ext.L();
                }
                string Contents =
              "Notes:\\P" +
              "    1. All dimensions are in m unless otherwise indicated.\\P" +
              "    2. The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer & architect before commencement of work.\\P" +
              "    3. All the produced unsuitable material shall be transport to the designate disposal area in a properly manner. \\P" +
              "    4. All the site activities and operations shall follow the requirement of the approved Health and Safety Managemen Plan strictly.\\P" +
              "    5. Concrete shall have the minimum 45MPa of cylinder compressive strength at 28 days.\\P" +
              "    6. Reinforcement steel shall have the minimum yield strength 500MPa.\\P" +
              "    7. Concrete cover shall be 0.050m for cross beam..";
                TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(-ext.W() * 0.5+15, -height), Contents, 1, 2.5, 250);
                exts.Add(ext);
                #endregion

                #region 第二页
                startPoint = startPoint.Convert3D(420);
                dicA = new Dictionary<string, Dictionary<string, string>>();
              
                if (typeName == "BPTM3S")
                {
                    dicT = new Dictionary<string, string>();
                    dicT.Add((length).ToString("0.000"), "string");
                    dicA.Add("TWIDTH", dicT);
                }
                else
                {                                      
                    dicT = new Dictionary<string, string>();
                    dicT.Add((length - 2 * 0.8).ToString("0.000"), "string");
                    dicA.Add("TWIDTH", dicT);                   
                }
                dicT = new Dictionary<string, string>();
                dicT.Add(((length - 2 * 0.8) * 0.5).ToString("0.000"), "string");
                dicA.Add("LEFTWIDTH", dicT);
                dicT = new Dictionary<string, string>();
                dicT.Add(((length - 2 * 0.8) * 0.5).ToString("0.000"), "string");
                dicA.Add("RIGHTWIDTH", dicT);

                ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                _blcName = typeName.Replace("B", "") + "-B1";
                db.CopyBlockFromFile(reberBlockPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(), scale, _blcName, reberBlockPath, dicA, null, ref ext);
                 height = ext.L() +5;
                _blcName = typeName.Replace("B", "") + "-B2";
                db.CopyBlockFromFile(reberBlockPath, _blcName);
                if (typeName == "BPTM3S")
                {
                    dicA = new Dictionary<string, Dictionary<string, string>>();
                    dicT = new Dictionary<string, string>();
                    dicT.Add((length).ToString("0.000"), "string");
                    dicA.Add("TWIDTH", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 0.8 -2.205 * 2) * 0.5).ToString("0.000"), "string");
                    dicA.Add("LEFTWIDTH", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 0.8 - 2.205 * 2) * 0.5).ToString("0.000"), "string");
                    dicA.Add("RIGHTWIDTH", dicT);
                }
                BlockTool.InsertBlockReference(startPoint.Convert3D(0, -height), scale, _blcName, reberBlockPath, dicA, null, ref ext);
                height = ext.L() - 15;              
                TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(-ext.W() * 0.5 + 15, -height), Contents, 1, 2.5, 250);
                exts.Add(ext);
                #endregion

                #region 第三页
                startPoint = startPoint.Convert3D(420,-height);
                ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                _blcName = typeName.Replace("B", "") + "-P";
                db.CopyBlockFromFile(reberBlockPath, _blcName);
                BlockTool.InsertBlockReference(startPoint.Convert3D(0, 0), 20, _blcName, reberBlockPath, dicA, null, ref ext);
            
                Contents = "Notes:\\P" +
              "     1. The lap length shall be increased by 40 percent for top horizontal reinforcement that more than 300mm of fresh concrete are placed below the reinforcement .\\P";
                if ( typeName == "BPTM1S")
                    TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(15, 8), Contents, 1, 2.5, 150);  
                else
                    TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(15, 5), Contents, 1, 2.5, 150);
                exts.Add(ext);
                #endregion
            }

        }

        /// <summary>
        /// 盖梁钢筋汇总表
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ret"></param>
        /// <param name="type"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="headName"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        public static Table DrawMergeBeamTable(Database db, MemberBase ret, EStructure type, ref Extents2d ext,
        Point3d startPoint, List<string> headName, string txtStyle, double scale)
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                Table tb = new Table();

                Dictionary<eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

                #region 统计合并数据
                foreach (RebarBase item in ret.RebarList)
                {
                    if (dic.Count == 0)
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                    else
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        dic.TryGetValue(item.Diameter, out items);
                        if (items == null || items.Count == 0)
                        {
                            items = new List<RebarBase>();
                        }
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                }
                #endregion

                #region 设置表格长宽
                int ubolt_row = 0;
                foreach (var item in dic.Keys)
                {
                    if (ret.UboltList.UBoltNum[item] > 0)
                    {
                        ubolt_row++;
                    }
                }

                int row = dic.Count + 2 + ubolt_row;
                int col = 5;



                tb.SetSize(row, col);
                tb.Position = startPoint;
                tb.GenerateLayout();
                #endregion

                #region 设置表头
                for (int i = 0; i < col; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i];
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                #endregion

                #region 设置表格值
                // 第一行第一列
                tb.Cells[1, 0].TextString = "Bars";
                tb.Cells[1, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 0].Contents[0].Rotation = 0;
                tb.Cells[1, 0].Contents[0].TextStyleId = id;

                // 第一列最后一行
                tb.Cells[dic.Count + 1, 0].TextString = "Concrete";
                tb.Cells[dic.Count + 1, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[dic.Count + 1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[dic.Count + 1, 0].Contents[0].Rotation = 0;
                tb.Cells[dic.Count + 1, 0].Contents[0].TextStyleId = id;

                // 其他数据
                #region Bars, Concreate数据
                double totalWeight = 0;
                for (int i = 1; i < row; ++i)
                {
                    if (i == dic.Count + 1)
                    {
                        tb.Cells[i, 1].TextString = string.Format("f'c={0}MPa", ret.ConcreteClass.ToString().Replace("C", ""));
                        tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 1].Contents[0].Rotation = 0;
                        tb.Cells[i, 1].Contents[0].TextStyleId = id;

                        tb.Cells[i, 2].TextString = "m3";
                        tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 2].Contents[0].Rotation = 0;
                        tb.Cells[i, 2].Contents[0].TextStyleId = id;

                        tb.Cells[i, 3].TextString = ret.ConcreteVolumn.ToString("0.000")/*string.Format("{0:N3}", ret.ConcreteVolumn)*/;
                        tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 3].Contents[0].Rotation = 0;
                        tb.Cells[i, 3].Contents[0].TextStyleId = id;
                    }
                    else
                    {
                        KeyValuePair<eDB, List<RebarBase>> pr = new KeyValuePair<eDB, List<RebarBase>>();
                        if (dic.Count > i - 1)
                        {
                            pr = dic.ElementAt(i - 1);
                        }
                        if (pr.Value == null)
                        {
                            continue;
                        }

                        // 类型
                        tb.Cells[i, 1].TextString = pr.Key.ToString();
                        tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 1].Contents[0].Rotation = 0;
                        tb.Cells[i, 1].Contents[0].TextStyleId = id;

                        // 单位
                        tb.Cells[i, 2].TextString = "kg";
                        tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 2].Contents[0].Rotation = 0;
                        tb.Cells[i, 2].Contents[0].TextStyleId = id;

                        // 数量
                        double weight = 0;
                        foreach (RebarBase info in pr.Value)
                        {
                            weight += info.TotalWeight;
                        }

                        tb.Cells[i, 3].TextString = weight.ToString("0.000")/* string.Format("{0:N3}", weight)*/;
                        tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 3].Contents[0].Rotation = 0;
                        tb.Cells[i, 3].Contents[0].TextStyleId = id;

                        // 总数
                        totalWeight += weight;
                    }

                    // 总数
                    tb.Cells[1, 4].TextString = totalWeight.ToString("0.000")/*string.Format("{0:N3}", totalWeight)*/;
                    tb.Cells[1, 4].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 4].Contents[0].Rotation = 0;
                    tb.Cells[1, 4].Contents[0].TextStyleId = id;
                }
                #endregion

                #region other数据  
                int index = 0;
                foreach (var item in dic.Keys)
                {
                    if (ret.UboltList.UBoltNum[item] > 0)
                    {
                        index++;
                        LoadBeamOtherTableData(tb, ret, id, "M10/U-bolt A(" + (int)item + "/" + (int)item + ")", ret.UboltList.UBoltNum[item], dic.Count + 1 + index, scale);
                    }
                }
                //LoadBeamOtherTableData(tb, ret, id, "M10/U-bolt A(25/25)", ret.UboltList.UBoltNum[eDB.DB25], dic.Count + 2, scale);
                //LoadBeamOtherTableData(tb, ret, id, "M10/U-bolt A(16/16)", ret.UboltList.UBoltNum[eDB.DB16], dic.Count + 3, scale);
                #endregion

                #endregion

                #region 设置行高、列宽
                for (int i = 0; i < col; ++i)
                {
                    if (i == 0)
                    {
                        tb.Columns[i].Width = 35 * scale;
                    }
                    else if (i == 1)
                    {
                        tb.Columns[i].Width = 60 * scale;
                    }
                    else if (i == 2)
                    {
                        tb.Columns[i].Width = 35 * scale;
                    }
                    else if (i == 3)
                    {
                        tb.Columns[i].Width = 48 * scale;
                    }
                    else if (i == 4)
                    {
                        tb.Columns[i].Width = 48 * scale;
                    }
                }

                for (int i = 0; i < row; ++i)
                {
                    tb.Rows[i].Height = 8 * scale;
                }
                #endregion

                #region 合并单元格
                List<CellRange> cellList = new List<CellRange>();

                CellRange range1 = CellRange.Create(tb, 1, 0, dic.Count, 0);
                cellList.Add(range1);

                CellRange range2 = CellRange.Create(tb, 1, 2, dic.Count, 2);
                cellList.Add(range2);

                CellRange range3 = CellRange.Create(tb, 1, 4, dic.Count, 4);
                cellList.Add(range3);

                CellRange range4 = CellRange.Create(tb, dic.Count + 1, 3, dic.Count + 1, 4);
                cellList.Add(range4);

                CellRange range5 = CellRange.Create(tb, 0, 0, 0, 1);
                cellList.Add(range5);


                if (ubolt_row > 0)
                {
                    for (int i = 1; i <= ubolt_row; i++)
                    {
                        CellRange range = CellRange.Create(tb, dic.Count + 1 + i, 3, dic.Count + 1 + i, 4);
                        cellList.Add(range);
                    }
                }
                //CellRange range6 = CellRange.Create(tb, dic.Count + 2, 3, dic.Count + 2, 4);
                //cellList.Add(range6);

                //CellRange range7 = CellRange.Create(tb, dic.Count + 3, 3, dic.Count + 3, 4);
                //cellList.Add(range7);

                foreach (CellRange range in cellList)
                {
                    tb.MergeCells(range);
                }
                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                tr.Commit();
                Extents3d ex3d = new Extents3d(tb.Bounds.Value.MinPoint.Convert3D(), tb.Bounds.Value.MaxPoint.Convert3D());
                ext = ex3d.Convert2D();
                return tb;
            }
        }

        #endregion

        #region 承台表格绘制
        /// <summary>
        /// 承台数据表
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="headName"></param>
        /// <param name="rowNum"></param>
        /// <param name="colNum"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="tbValue"></param>
        /// <param name="typeName"></param>
        /// <param name="structureName"></param>
        /// <param name="type"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>
        public static Table DrawFootTable(Database db, ref Extents2d ext, Point3d startPoint,
      int rowNum, string txtStyle, double scale, RebarCollection tbValue, string typeName,
      string structureName, FDEE.Model.eSubType type, int pageCount = 0)
        {
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");

            tbH = 0;
            int cuRCount = 0;//当前页行高小于块高度的数量
            int curAllRow = 0;//当前页行数
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                //int rowNum = tbValue.Count + 2;
                // 创建table 
                startPoint = startPoint.Convert3D(420 * pageCount);
                Table tb = new Table();
                int colNum = headName.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 第一页
                #region 第一行 标题
                tb.Cells[0, 0].TextString = String.Format("TABLE OF REINFORCEMENT BAR LIST (FOOTING {0}{1}{2} COLUMN HEIGHT {3})", "\"", structureName, "\"",
                    Common.GetPierHeightDes(typeName, type));
                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                tb.ScaleFactors = new Scale3d(1);
                //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                #endregion
                tb.Rows[0].Height = 9 * scale;

                #region 第二行 表格标题
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                #endregion

                tb.Rows[1].Height = 16 * scale;

                #region 设置表格值
                if (tbValue.Count > 0)
                {
                    for (int m = 0; m < tbValue.Count; m++)
                    {
                        try
                        {
                            //
                            string value = "";
                            int n = 0;
                            value = tbValue[m].MBarMark.ToString();
                            if (tbValue[m].SBarMark != 0)
                                value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                            else
                                value = tbValue[m].MBarMark.ToString() + tbValue[m].CBarMark;
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            n++;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //Formula
                            n = n + 2;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //R
                            n++;
                            value = "";
                            if (tbValue[m].R != 0)
                                value = tbValue[m].R.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //d
                            n++;
                            value = "";
                            if (tbValue[m].Diameter != 0)
                            {
                                value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                            }
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //r
                            n++;
                            value = "";
                            if (tbValue[m].r != 0)
                                value = tbValue[m].r.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //h
                            n++;
                            value = "";
                            if (tbValue[m].h != 0)
                                value = tbValue[m].h.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //n
                            n++;
                            value = "";
                            if (tbValue[m].n != 0)
                                value = tbValue[m].n.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Lx
                            n++;
                            value = "";
                            if (tbValue[m].Lx != 0)
                                value = tbValue[m].Lx.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //A
                            n++;
                            value = "";
                            if (tbValue[m].A != 0)
                                value = tbValue[m].A.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //B
                            n++;
                            value = "";
                            if (tbValue[m].B != 0)
                                value = tbValue[m].B.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //C
                            n++;
                            value = "";
                            if (tbValue[m].C != 0)
                                value = tbValue[m].C.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //D
                            n++;
                            value = "";
                            if (tbValue[m].D != 0)
                                value = tbValue[m].D.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Quantity
                            n++;
                            value = "";
                            if (tbValue[m].Quantity != 0)
                                value = tbValue[m].Quantity.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Length
                            n++;
                            value = "";
                            if (tbValue[m].Length != 0)
                                value = tbValue[m].Length.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000"); //获取i行j列数据
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalLength
                            n++;
                            value = "";
                            if (tbValue[m].TotalLength != 0)
                                value = tbValue[m].TotalLength.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000")/*string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //UnitWeight
                            n++;
                            value = "";
                            if (tbValue[m].UnitWeight != 0)
                                value = tbValue[m].UnitWeight.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000")/* string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalWeight
                            n++;
                            value = "";
                            if (tbValue[m].TotalWeight != 0)
                                value = tbValue[m].TotalWeight.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = double.Parse(value).ToString("0.000") /*string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }
                            if (typeName != "FMHK")
                            {
                                if ((tbValue[m].MBarMark == 1 || tbValue[m].MBarMark == 2) && tbValue[m].ShapeConfg.ToString().Contains("MI"))
                                    _blcName = "MI12";
                                else if ((tbValue[m].MBarMark == 1 || tbValue[m].MBarMark == 2) && tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                    _blcName = "MA12B";
                                if ((tbValue[m].MBarMark == 3 || tbValue[m].MBarMark == 4) && tbValue[m].ShapeConfg.ToString().Contains("MI"))
                                    _blcName = "MI34";
                                if (tbValue[m].MBarMark == 5 && tbValue[m].SBarMark == 1 && tbValue[m].ShapeConfg.ToString().Contains("MI"))
                                    _blcName = "MI51A";
                                if (tbValue[m].MBarMark == 5 && tbValue[m].SBarMark == 2 && tbValue[m].ShapeConfg.ToString().Contains("MI"))
                                    _blcName = "MI51B";
                                if (tbValue[m].MBarMark == 6 && tbValue[m].ShapeConfg.ToString().Contains("MHXe"))
                                    _blcName = "MHXe";
                                else if (tbValue[m].MBarMark == 6 && tbValue[m].ShapeConfg.ToString().Contains("MHX"))
                                    _blcName = "MHX";
                            }
                            else
                            {
                                if ((tbValue[m].MBarMark == 1 || tbValue[m].MBarMark == 2) && tbValue[m].ShapeConfg.ToString().Contains("MI"))
                                    _blcName = "MI12";
                                else if ((tbValue[m].MBarMark == 1 || tbValue[m].MBarMark == 2) && tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                    _blcName = "MA12B";
                                else if ((tbValue[m].MBarMark == 3 || tbValue[m].MBarMark == 4) && tbValue[m].ShapeConfg.ToString().Contains("MI"))
                                    _blcName = "MI34";
                                else if(tbValue[m].MBarMark == 5 && (tbValue[m].SBarMark ==0|| tbValue[m].SBarMark == 1) && tbValue[m].ShapeConfg.ToString().Contains("MI"))
                                    _blcName = "MI51A";
                                else if(tbValue[m].MBarMark == 5 && (tbValue[m].SBarMark == 2) && tbValue[m].ShapeConfg.ToString().Contains("MI"))
                                    _blcName = "MI51B";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MI"))
                                    _blcName = "MI";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                    _blcName = "MA";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MLL"))
                                    _blcName = "MLL";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MLR"))
                                    _blcName = "MLR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCT"))
                                    _blcName = "MCT";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCB"))
                                    _blcName = "MCB";
                            }
                            db.CopyBlockFromFile(_dwgPath, _blcName);
                  
                            BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 16 * m + 8)), 0.8, _blcName, _dwgPath, 0);
                            
                        }
                        catch (Exception ex)
                        { }
                    }
                }

                #endregion

                #region 表格添加数据

                #endregion

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = 4 * 3 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 16 * 3 * scale;
                    else if (i == 3)
                        tb.Columns[i].Width = 11 * 3 * scale;
                    else if (i > headName.Count - 4)
                        tb.Columns[i].Width = 9 * 3 * scale;
                    else if (i > headName.Count - 6)
                        tb.Columns[i].Width = 8 * 3 * scale;
                    else
                        tb.Columns[i].Width = 4 * 3 * scale;
                }
                #endregion

                //行高
                for (int i = 2; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 16 * scale;
                }

                #region 列单元格合并

                ////合并数据定义
                //Dictionary<int, int> dic = new Dictionary<int, int>();
                //int rowIndex = 0;
                //int num = 0;
                //string stShape = tbValue[0].ShapeConfg.ToString();//要合并的类型
                //string stDia = tbValue[0].Diameter.ToString();//要合并的钢筋直径
                //for (int i = 0; i < tbValue.Count; ++i)
                //{
                //    //同样的直径和类型合并
                //    if (tbValue[i].ShapeConfg.ToString() == stShape&& tbValue[i].Diameter.ToString() == stDia)
                //    {
                //        num++;
                //    }
                //    else
                //    {

                //        dic.Add(rowIndex, num);
                //        num = 1;
                //        rowIndex = i;
                //        //下一条要合并的直径和类型
                //        stDia = tbValue[i].Diameter.ToString();
                //        stShape = tbValue[i].ShapeConfg.ToString();
                //    }
                //    if (i == tbValue.Count - 1)
                //        dic.Add(rowIndex, num);
                //}

                // 列单元格合并
                //int topRow = 2;

                //List<CellRange> cellList = new List<CellRange>();

                //foreach (KeyValuePair<int, int> pr in dic)
                //{
                //    curAllRow += pr.Value;
                //    lastMegerHeight = pr.Value * 6.5 * scale;
                //    tb.Cells[topRow, 2].Alignment = CellAlignment.MiddleCenter;
                //    if (pr.Value < 4)
                //    {
                //        for (int i = 0; i < pr.Value; i++)
                //        {
                //            tb.Rows[topRow+i].Height = intervalHeight / pr.Value;                            
                //        }
                //        cuRCount++;
                //        curAllRow -= pr.Value;
                //        lastMegerHeight =32 * scale;

                //    }

                //    db.CopyBlockFromFile(_dwgPath, _blcName);
                //    BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8*3 * scale, -(7 * scale + 12 * scale + intervalHeight * cuRCount+ 6.5  * curAllRow - lastMegerHeight * 0.4)), 1, _blcName, _dwgPath, 0);
                //    CellRange range = CellRange.Create(tb, topRow, 2, topRow + pr.Value - 1, 2);


                //    cellList.Add(range);
                //    topRow += pr.Value;

                //}
                //foreach (CellRange range in cellList)
                //{
                //    tb.MergeCells(range);
                //}

                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                #endregion

                #region 其他页

                #endregion
                tr.Commit();
                return tb;
            }
        }

        /// <summary>
        /// 承台汇总表
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ret"></param>
        /// <param name="type"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="headName"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        public static Table DrawMergeFootingTable(Database db, MemberBase ret, EStructure type, ref Extents2d ext,
        Point3d startPoint, List<string> headName, string txtStyle, double scale)
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                Table tb = new Table();

                Dictionary<eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

                #region 统计合并数据
                foreach (RebarBase item in ret.RebarList)
                {
                    if (item.MBarMark < 6)
                    {
                        if (dic.Count == 0)
                        {
                            List<RebarBase> items = new List<RebarBase>();
                            items.Add(item);
                            dic[item.Diameter] = items;
                        }
                        else
                        {
                            List<RebarBase> items = new List<RebarBase>();
                            dic.TryGetValue(item.Diameter, out items);
                            if (items == null || items.Count == 0)
                            {
                                items = new List<RebarBase>();
                            }
                            items.Add(item);
                            dic[item.Diameter] = items;
                        }
                    }
                }
                #endregion

                #region 设置表格长宽
                bool isLoadOther = false;
                int row = dic.Count + 2;
                int col = 5;
                switch (type)
                {
                    case EStructure.E_CAPBEAM:
                        {
                            // 盖梁
                            break;
                        }
                    case EStructure.E_COLUMN:
                        {
                            // 墩柱
                            row = dic.Count + 3;
                            isLoadOther = true;
                            break;
                        }
                    case EStructure.E_FOOT:
                        {
                            // 承台
                            row = dic.Count + 2;
                            break;
                        }
                    case EStructure.E_PILE:
                        {
                            // 桩基
                            row = dic.Count + 9;
                            isLoadOther = true;
                            break;
                        }
                    default:
                        break;
                }

                tb.SetSize(row, col);
                tb.Position = startPoint;
                tb.GenerateLayout();
                #endregion

                #region 设置表头
                for (int i = 0; i < col; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i];
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                #endregion

                #region 设置表格值
                // 第一行第一列
                tb.Cells[1, 0].TextString = "Bars";
                tb.Cells[1, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 0].Contents[0].Rotation = 0;
                tb.Cells[1, 0].Contents[0].TextStyleId = id;

                // 第一列最后一行
                tb.Cells[dic.Count + 1, 0].TextString = "Concrete";
                tb.Cells[dic.Count + 1, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[dic.Count + 1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[dic.Count + 1, 0].Contents[0].Rotation = 0;
                tb.Cells[dic.Count + 1, 0].Contents[0].TextStyleId = id;

                // 其他数据
                #region Bars, Concreate数据
                double totalWeight = 0;
                for (int i = 1; i < row; ++i)
                {
                    if (i == dic.Count + 1)
                    {
                        tb.Cells[i, 1].TextString = string.Format("f'c={0}MPa", ret.ConcreteClass.ToString().Replace("C", ""));
                        tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 1].Contents[0].Rotation = 0;
                        tb.Cells[i, 1].Contents[0].TextStyleId = id;

                        tb.Cells[i, 2].TextString = "m3";
                        tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 2].Contents[0].Rotation = 0;
                        tb.Cells[i, 2].Contents[0].TextStyleId = id;

                        tb.Cells[i, 3].TextString = ret.ConcreteVolumn.ToString("0.000")/*string.Format("{0:N3}", ret.ConcreteVolumn)*/;
                        tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 3].Contents[0].Rotation = 0;
                        tb.Cells[i, 3].Contents[0].TextStyleId = id;
                    }
                    else
                    {
                        KeyValuePair<eDB, List<RebarBase>> pr = new KeyValuePair<eDB, List<RebarBase>>();
                        if (dic.Count > i - 1)
                        {
                            pr = dic.ElementAt(i - 1);
                        }
                        if (pr.Value == null)
                        {
                            continue;
                        }

                        // 类型
                        tb.Cells[i, 1].TextString = pr.Key.ToString();
                        tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 1].Contents[0].Rotation = 0;
                        tb.Cells[i, 1].Contents[0].TextStyleId = id;

                        // 单位
                        tb.Cells[i, 2].TextString = "kg";
                        tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 2].Contents[0].Rotation = 0;
                        tb.Cells[i, 2].Contents[0].TextStyleId = id;

                        // 数量
                        double weight = 0;
                        foreach (RebarBase info in pr.Value)
                        {
                            weight += info.TotalWeight;
                        }

                        tb.Cells[i, 3].TextString = weight.ToString("0.000")/* string.Format("{0:N3}", weight)*/;
                        tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 3].Contents[0].Rotation = 0;
                        tb.Cells[i, 3].Contents[0].TextStyleId = id;

                        // 总数
                        totalWeight += weight;
                    }

                    // 总数
                    tb.Cells[1, 4].TextString = totalWeight.ToString("0.000")/*string.Format("{0:N3}", totalWeight)*/;
                    tb.Cells[1, 4].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 4].Contents[0].Rotation = 0;
                    tb.Cells[1, 4].Contents[0].TextStyleId = id;
                }
                #endregion

                #endregion

                #region 设置行高、列宽
                for (int i = 0; i < col; ++i)
                {
                    if (i == 0)
                    {
                        tb.Columns[i].Width = 30 * scale;
                    }
                    else if (i == 1)
                    {
                        tb.Columns[i].Width = 50 * scale;
                    }
                    else if (i == 2)
                    {
                        tb.Columns[i].Width = 30 * scale;
                    }
                    else if (i == 3)
                    {
                        tb.Columns[i].Width = 40 * scale;
                    }
                    else if (i == 4)
                    {
                        tb.Columns[i].Width = 40 * scale;
                    }
                }

                for (int i = 0; i < row; ++i)
                {
                    tb.Rows[i].Height = 8 * scale;
                }
                #endregion

                #region 合并单元格
                List<CellRange> cellList = new List<CellRange>();

                CellRange range1 = CellRange.Create(tb, 1, 0, dic.Count, 0);
                cellList.Add(range1);

                CellRange range2 = CellRange.Create(tb, 1, 2, dic.Count, 2);
                cellList.Add(range2);

                CellRange range3 = CellRange.Create(tb, 1, 4, dic.Count, 4);
                cellList.Add(range3);

                CellRange range4 = CellRange.Create(tb, dic.Count + 1, 3, dic.Count + 1, 4);
                cellList.Add(range4);

                CellRange range5 = CellRange.Create(tb, 0, 0, 0, 1);
                cellList.Add(range5);

                if (isLoadOther)
                {
                    CellRange range6 = CellRange.Create(tb, dic.Count + 2, 0, tb.Rows.Count - 1, 0);
                    cellList.Add(range6);

                    CellRange range7 = CellRange.Create(tb, dic.Count + 2, 2, tb.Rows.Count - 1, 2);
                    cellList.Add(range7);

                    CellRange range8 = CellRange.Create(tb, dic.Count + 2, 3, dic.Count + 2, 4);
                    cellList.Add(range8);

                    CellRange range9 = CellRange.Create(tb, dic.Count + 3, 3, dic.Count + 3, 4);
                    cellList.Add(range9);

                    CellRange range10 = CellRange.Create(tb, dic.Count + 4, 3, dic.Count + 4, 4);
                    cellList.Add(range10);

                    CellRange range11 = CellRange.Create(tb, dic.Count + 5, 3, dic.Count + 5, 4);
                    cellList.Add(range11);

                    CellRange range12 = CellRange.Create(tb, dic.Count + 6, 3, dic.Count + 6, 4);
                    cellList.Add(range12);

                    CellRange range13 = CellRange.Create(tb, dic.Count + 7, 3, dic.Count + 7, 4);
                    cellList.Add(range13);

                    CellRange range14 = CellRange.Create(tb, dic.Count + 8, 3, dic.Count + 8, 4);
                    cellList.Add(range14);
                }

                foreach (CellRange range in cellList)
                {
                    tb.MergeCells(range);
                }
                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                tr.Commit();
                Extents3d ex3d = new Extents3d(tb.Bounds.Value.MinPoint.Convert3D(), tb.Bounds.Value.MaxPoint.Convert3D());
                ext = ex3d.Convert2D();
                return tb;
            }
        }
        #endregion

        #region 墩柱表格
        /// <summary>
        /// 墩柱汇总表
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ret"></param>
        /// <param name="type"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="headName"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        public static Table DrawMergeColumnTable(Database db, MemberBase ret, EStructure type, ref Extents2d ext,
  Point3d startPoint, List<string> headName, string txtStyle, double scale)
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                Table tb = new Table();

                Dictionary<eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

                #region 统计合并数据
                foreach (RebarBase item in ret.RebarList)
                {
                    if (dic.Count == 0)
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                    else
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        dic.TryGetValue(item.Diameter, out items);
                        if (items == null || items.Count == 0)
                        {
                            items = new List<RebarBase>();
                        }
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                }
                #endregion

                #region 设置表格长宽
                int ubolt_row = 0;
                foreach (var item in dic.Keys)
                {
                    if (ret.UboltList.UBoltNum[item] > 0)
                    {
                        ubolt_row++;
                    }
                }

                int row = dic.Count + 2 + ubolt_row;
                int col = 5;

                //int row = dic.Count + 2;
                //int col = 5;
                //row = dic.Count + 3;


                tb.SetSize(row, col);
                tb.Position = startPoint;
                tb.GenerateLayout();
                #endregion

                #region 设置表头
                for (int i = 0; i < col; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i];
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                #endregion

                #region 设置表格值
                // 第一行第一列
                tb.Cells[1, 0].TextString = "Bars";
                tb.Cells[1, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 0].Contents[0].Rotation = 0;
                tb.Cells[1, 0].Contents[0].TextStyleId = id;

                // 第一列最后一行
                tb.Cells[dic.Count + 1, 0].TextString = "Concrete";
                tb.Cells[dic.Count + 1, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[dic.Count + 1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[dic.Count + 1, 0].Contents[0].Rotation = 0;
                tb.Cells[dic.Count + 1, 0].Contents[0].TextStyleId = id;

                // 其他数据
                #region Bars, Concreate数据
                double totalWeight = 0;
                for (int i = 1; i < row; ++i)
                {
                    if (i == dic.Count + 1)
                    {
                        tb.Cells[i, 1].TextString = string.Format("f'c={0}MPa", ret.ConcreteClass.ToString().Replace("C", ""));
                        tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 1].Contents[0].Rotation = 0;
                        tb.Cells[i, 1].Contents[0].TextStyleId = id;

                        tb.Cells[i, 2].TextString = "m3";
                        tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 2].Contents[0].Rotation = 0;
                        tb.Cells[i, 2].Contents[0].TextStyleId = id;

                        tb.Cells[i, 3].TextString = ret.ConcreteVolumn.ToString("0.000")/*string.Format("{0:N3}", ret.ConcreteVolumn)*/;
                        tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 3].Contents[0].Rotation = 0;
                        tb.Cells[i, 3].Contents[0].TextStyleId = id;
                    }
                    else
                    {
                        KeyValuePair<eDB, List<RebarBase>> pr = new KeyValuePair<eDB, List<RebarBase>>();
                        if (dic.Count > i - 1)
                        {
                            pr = dic.ElementAt(i - 1);
                        }
                        if (pr.Value == null)
                        {
                            continue;
                        }

                        // 类型
                        tb.Cells[i, 1].TextString = pr.Key.ToString();
                        tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 1].Contents[0].Rotation = 0;
                        tb.Cells[i, 1].Contents[0].TextStyleId = id;

                        // 单位
                        tb.Cells[i, 2].TextString = "kg";
                        tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 2].Contents[0].Rotation = 0;
                        tb.Cells[i, 2].Contents[0].TextStyleId = id;

                        // 数量
                        double weight = 0;
                        foreach (RebarBase info in pr.Value)
                        {
                            weight += info.TotalWeight;
                        }

                        tb.Cells[i, 3].TextString = weight.ToString("0.000")/* string.Format("{0:N3}", weight)*/;
                        tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 3].Contents[0].Rotation = 0;
                        tb.Cells[i, 3].Contents[0].TextStyleId = id;

                        // 总数
                        totalWeight += weight;
                    }

                    // 总数
                    tb.Cells[1, 4].TextString = totalWeight.ToString("0.000")/*string.Format("{0:N3}", totalWeight)*/;
                    tb.Cells[1, 4].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 4].Contents[0].Rotation = 0;
                    tb.Cells[1, 4].Contents[0].TextStyleId = id;
                }
                #endregion

                #region other数据               
                //LoadColunmOtherTableData(tb, ret, id, ret.UAN1N2, dic.Count + 2, scale);
                int index = 0;
                foreach (var item in dic.Keys)
                {
                    if (ret.UboltList.UBoltNum[item] > 0)
                    {
                        index++;
                        LoadBeamOtherTableData(tb, ret, id, "M10/U-bolt A(" + (int)item + "/" + (int)item + ")", ret.UboltList.UBoltNum[item], dic.Count + 1 + index, scale);
                    }
                }
                #endregion

                #endregion

                #region 设置行高、列宽
                for (int i = 0; i < col; ++i)
                {
                    if (i == 0)
                    {
                        tb.Columns[i].Width = 35 * scale;
                    }
                    else if (i == 1)
                    {
                        tb.Columns[i].Width = 60 * scale;
                    }
                    else if (i == 2)
                    {
                        tb.Columns[i].Width = 35 * scale;
                    }
                    else if (i == 3)
                    {
                        tb.Columns[i].Width = 48 * scale;
                    }
                    else if (i == 4)
                    {
                        tb.Columns[i].Width = 48 * scale;
                    }
                }

                for (int i = 0; i < row; ++i)
                {
                    tb.Rows[i].Height = 8 * scale;
                }
                #endregion

                #region 合并单元格
                List<CellRange> cellList = new List<CellRange>();

                CellRange range1 = CellRange.Create(tb, 1, 0, dic.Count, 0);
                cellList.Add(range1);

                CellRange range2 = CellRange.Create(tb, 1, 2, dic.Count, 2);
                cellList.Add(range2);

                CellRange range3 = CellRange.Create(tb, 1, 4, dic.Count, 4);
                cellList.Add(range3);

                CellRange range4 = CellRange.Create(tb, dic.Count + 1, 3, dic.Count + 1, 4);
                cellList.Add(range4);

                CellRange range5 = CellRange.Create(tb, 0, 0, 0, 1);
                cellList.Add(range5);


                if (ubolt_row > 0)
                {
                    for (int i = 1; i <= ubolt_row; i++)
                    {
                        CellRange range = CellRange.Create(tb, dic.Count + 1 + i, 3, dic.Count + 1 + i, 4);
                        cellList.Add(range);
                    }
                }
                //CellRange range6 = CellRange.Create(tb, dic.Count + 2, 3, dic.Count + 2, 4);
                //cellList.Add(range6);


                foreach (CellRange range in cellList)
                {
                    tb.MergeCells(range);
                }
                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                tr.Commit();
                Extents3d ex3d = new Extents3d(tb.Bounds.Value.MinPoint.Convert3D(), tb.Bounds.Value.MaxPoint.Convert3D());
                ext = ex3d.Convert2D();
                return tb;
            }
        }


        /// <summary>
        /// 批量墩柱汇总
        /// </summary>
        /// <param name="db"></param>
        /// <param name="rets"></param>
        /// <param name="pierHeight"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="type"></param>
        /// <param name="title"></param>
        /// <param name="num"></param>
        public static void DrawColumnListMergeTable(Database db, List<MemberBase> rets, List<int> pierHeight, ref Extents2d ext,
     Point3d startPoint, string txtStyle, double scale, string type = "C-PTM2-C", string title = "MAINLINE", int num = 2, string tkPath = "")
        {

            Table tb = new Table();
            List<Dictionary<eDB, List<RebarBase>>> dicList = new List<Dictionary<eDB, List<RebarBase>>>();
            int totalUb = 0;
            foreach (MemberBase ret in rets)
            {
                if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
                {
                    throw new Exception("数据异常");
                }

                Dictionary<eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

                #region 统计合并数据
                foreach (RebarBase item in ret.RebarList)
                {
                    if (dic.Count == 0)
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                    else
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        dic.TryGetValue(item.Diameter, out items);
                        if (items == null || items.Count == 0)
                        {
                            items = new List<RebarBase>();
                        }
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                }
                dicList.Add(dic);

                totalUb += ret.UAN1N2 * num;
                #endregion

            }

            //#region 设置表格长宽

            int row = 1 + 4 + 4 + (dicList[0].Count - 2);
            if (totalUb == 0)
                row = 4 + 4 + (dicList[0].Count - 2);
            int col = 6 + rets.Count;

            tb.SetSize(row, col);
            tb.Position = startPoint;
            tb.GenerateLayout();
            //#endregion

            #region 设置表头
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                if (rets.Count > 2)
                {
                    tb.Cells[0, 0].TextString = String.Format("COLUMN LIST AND QUANTITIES FOR {0} TO {1} OF " + title + "({2} COLUMNS)",
                      rets[0].PierNumber, rets[rets.Count - 1].PierNumber, rets.Count * num);
                }
                else
                {
                    string pierNum = "";
                    foreach (MemberBase item in rets)
                    {
                        if (string.IsNullOrWhiteSpace(pierNum))
                            pierNum = item.PierNumber;
                        else
                            pierNum += "," + item.PierNumber;
                    }
                    tb.Cells[0, 0].TextString = String.Format("COLUMN LIST AND QUANTITIES FOR {0}  OF " + title + "({1} COLUMNS)",
                     pierNum, rets.Count * num);
                }
                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;

                tb.Cells[1, 0].TextString = "Items";
                tb.Cells[1, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 0].Contents[0].Rotation = 0;
                tb.Cells[1, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 0, 4, 2));

                tb.Cells[1, 3].TextString = "unit";
                tb.Cells[1, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 3].Contents[0].Rotation = 0;
                tb.Cells[1, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 3, 4, 3));

                tb.Cells[1, 4].TextString = "Column";
                tb.Cells[1, 4].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 4].Contents[0].Rotation = 0;
                tb.Cells[1, 4].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 4, 1, 4 + rets.Count - 1));

                for (int i = 0; i < rets.Count; i++)
                {
                    tb.Cells[2, 4 + i].TextString = rets[i].PierNumber;
                    tb.Cells[2, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[2, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[2, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[2, 4 + i].Contents[0].TextStyleId = id;

                    tb.Cells[3, 4 + i].TextString = type;
                    tb.Cells[3, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[3, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[3, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[3, 4 + i].Contents[0].TextStyleId = id;

                    tb.Cells[4, 4 + i].TextString = "Height=" + pierHeight[i] * 0.001 + "m";
                    tb.Cells[4, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[4, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[4, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[4, 4 + i].Contents[0].TextStyleId = id;
                }


                tb.Cells[1, 4 + rets.Count].TextString = "Total";
                tb.Cells[1, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 4 + rets.Count].Contents[0].Rotation = 0;
                tb.Cells[1, 4 + rets.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 4 + rets.Count, 4, 4 + rets.Count + 1));



                tb.Cells[5, 0].TextString = "Column Qty.";
                tb.Cells[5, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[5, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[5, 0].Contents[0].Rotation = 0;
                tb.Cells[5, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 5, 0, 5, 2));

                tb.Cells[5, 3].TextString = "Number";
                tb.Cells[5, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[5, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[5, 3].Contents[0].Rotation = 0;
                tb.Cells[5, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 5, 3, 5, 3));

                for (int i = 0; i < rets.Count; i++)
                {
                    //if (rets[i].PierNumber == "P-214")
                    //    num = 2;
                    //else
                    //    num = 1;
                    tb.Cells[5, 4 + i].TextString = num.ToString();
                    tb.Cells[5, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[5, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[5, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[5, 4 + i].Contents[0].TextStyleId = id;
                }

                tb.Cells[5, 4 + rets.Count].TextString = (num * rets.Count).ToString();
                tb.Cells[5, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[5, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[5, 4 + rets.Count].Contents[0].Rotation = 0;
                tb.Cells[5, 4 + rets.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 5, 4 + rets.Count, 5, 4 + rets.Count + 1));

                if (dicList[0].Count == 2)
                {
                    tb.Cells[6, 0].TextString = "Material";
                    tb.Cells[6, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 0].Contents[0].Rotation = 0;
                    tb.Cells[6, 0].Contents[0].TextStyleId = id;
                    if (totalUb != 0)
                    {
                        tb.MergeCells(CellRange.Create(tb, 6, 0, 8, 0));
                    }
                    else
                    {
                        tb.MergeCells(CellRange.Create(tb, 6, 0, 7, 0));
                    }

                    tb.Cells[6, 1].TextString = "Bars";
                    tb.Cells[6, 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 1].Contents[0].Rotation = 0;
                    tb.Cells[6, 1].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 6, 1, 7, 1));

                    tb.Cells[6, 2].TextString = "DB12";
                    tb.Cells[6, 2].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 2].Contents[0].Rotation = 0;
                    tb.Cells[6, 2].Contents[0].TextStyleId = id;

                    try
                    {
                        foreach (RebarBase info in dicList[0][eDB.DB32])
                        {
                            double w = info.TotalWeight;
                        }
                        tb.Cells[7, 2].TextString = "DB32";
                    }
                    catch
                    {
                        tb.Cells[7, 2].TextString = "DB28";
                    }
                    tb.Cells[7, 2].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[7, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[7, 2].Contents[0].Rotation = 0;
                    tb.Cells[7, 2].Contents[0].TextStyleId = id;

                    tb.Cells[6, 3].TextString = "kg";
                    tb.Cells[6, 3].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 3].Contents[0].Rotation = 0;
                    tb.Cells[6, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 6, 3, 7, 3));
                    if (totalUb != 0)
                    {
                        tb.Cells[8, 1].TextString = "U-bolt A";
                        tb.Cells[8, 1].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[8, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[8, 1].Contents[0].Rotation = 0;
                        tb.Cells[8, 1].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 8, 1, 8, 2));

                        tb.Cells[8, 3].TextString = "Number";
                        tb.Cells[8, 3].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[8, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[8, 3].Contents[0].Rotation = 0;
                        tb.Cells[8, 3].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 8, 3, 8, 3));
                    }
                }
                else
                {
                    tb.Cells[6, 0].TextString = "Material";
                    tb.Cells[6, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 0].Contents[0].Rotation = 0;
                    tb.Cells[6, 0].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 6, 0, 6 + dicList[0].Count, 0));

                    tb.Cells[6, 1].TextString = "Bars";
                    tb.Cells[6, 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 1].Contents[0].Rotation = 0;
                    tb.Cells[6, 1].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 6, 1, 6 + dicList[0].Count - 1, 1));

                    for (int n = 0; n < dicList[0].Count; n++)
                    {
                        tb.Cells[6 + n, 2].TextString = dicList[0].Keys.ToList()[n].ToString();
                        tb.Cells[6 + n, 2].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[6 + n, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[6 + n, 2].Contents[0].Rotation = 0;
                        tb.Cells[6 + n, 2].Contents[0].TextStyleId = id;
                    }
                    //tb.Cells[6, 2].TextString = "DB12";
                    //tb.Cells[6, 2].Contents[0].TextHeight = 2.5 * scale;
                    //tb.Cells[6, 2].Alignment = CellAlignment.MiddleCenter;
                    //tb.Cells[6, 2].Contents[0].Rotation = 0;
                    //tb.Cells[6, 2].Contents[0].TextStyleId = id;

                    //try
                    //{
                    //    foreach (RebarBase info in dicList[0][eDB.DB32])
                    //    {
                    //        double w = info.TotalWeight;
                    //    }
                    //    tb.Cells[7, 2].TextString = "DB32";
                    //}
                    //catch
                    //{
                    //    tb.Cells[7, 2].TextString = "DB28";
                    //}
                    //tb.Cells[7, 2].Contents[0].TextHeight = 2.5 * scale;
                    //tb.Cells[7, 2].Alignment = CellAlignment.MiddleCenter;
                    //tb.Cells[7, 2].Contents[0].Rotation = 0;
                    //tb.Cells[7, 2].Contents[0].TextStyleId = id;

                    tb.Cells[6, 3].TextString = "kg";
                    tb.Cells[6, 3].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 3].Contents[0].Rotation = 0;
                    tb.Cells[6, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 6, 3, 6 + dicList[0].Count - 1, 3));
                    if (totalUb != 0)
                    {
                        tb.Cells[6 + dicList[0].Count, 1].TextString = "U-bolt A";
                        tb.Cells[6 + dicList[0].Count, 1].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[6 + dicList[0].Count, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[6 + dicList[0].Count, 1].Contents[0].Rotation = 0;
                        tb.Cells[6 + dicList[0].Count, 1].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 6 + dicList[0].Count, 1, 6 + dicList[0].Count, 2));

                        tb.Cells[6 + dicList[0].Count, 3].TextString = "Number";
                        tb.Cells[6 + dicList[0].Count, 3].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[6 + dicList[0].Count, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[6 + dicList[0].Count, 3].Contents[0].Rotation = 0;
                        tb.Cells[6 + dicList[0].Count, 3].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 6 + dicList[0].Count, 3, 6 + dicList[0].Count, 3));
                    }
                }
                if (dicList[0].Count == 2)
                {
                    double total12weight = 0;
                    double total32weight = 0;
                    int totalUblot = 0;
                    for (int i = 0; i < rets.Count; i++)
                    {
                        //if (rets[i].PierNumber == "P-214")
                        //    num = 2;
                        //else
                        //    num = 1;
                        double weight = 0;
                        foreach (RebarBase info in dicList[i][eDB.DB12])
                        {
                            weight += info.TotalWeight;
                        }
                        weight = weight * num;
                        tb.Cells[6, 4 + i].TextString = weight.ToString("0.000"); ;
                        tb.Cells[6, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[6, 4 + i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[6, 4 + i].Contents[0].Rotation = 0;
                        tb.Cells[6, 4 + i].Contents[0].TextStyleId = id;

                        total12weight += weight;

                        weight = 0;
                        try
                        {
                            foreach (RebarBase info in dicList[i][eDB.DB32])
                            {
                                weight += info.TotalWeight;
                            }
                        }
                        catch
                        {
                            foreach (RebarBase info in dicList[i][eDB.DB28])
                            {
                                weight += info.TotalWeight;
                            }
                        }

                        weight = weight * num;
                        tb.Cells[7, 4 + i].TextString = weight.ToString("0.000"); ;
                        tb.Cells[7, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[7, 4 + i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[7, 4 + i].Contents[0].Rotation = 0;
                        tb.Cells[7, 4 + i].Contents[0].TextStyleId = id;

                        total32weight += weight;
                        if (totalUb != 0)
                        {
                            tb.Cells[8, 4 + i].TextString = (rets[i].UAN1N2 * num).ToString();
                            tb.Cells[8, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                            tb.Cells[8, 4 + i].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[8, 4 + i].Contents[0].Rotation = 0;
                            tb.Cells[8, 4 + i].Contents[0].TextStyleId = id;

                            totalUblot += rets[i].UAN1N2 * num;
                        }
                    }

                    tb.Cells[6, 4 + rets.Count].TextString = total12weight.ToString();
                    tb.Cells[6, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 4 + rets.Count].Contents[0].Rotation = 0;
                    tb.Cells[6, 4 + rets.Count].Contents[0].TextStyleId = id;

                    tb.Cells[7, 4 + rets.Count].TextString = total32weight.ToString();
                    tb.Cells[7, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[7, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[7, 4 + rets.Count].Contents[0].Rotation = 0;
                    tb.Cells[7, 4 + rets.Count].Contents[0].TextStyleId = id;

                    tb.Cells[6, 4 + rets.Count + 1].TextString = (total12weight + total32weight).ToString();
                    tb.Cells[6, 4 + rets.Count + 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 4 + rets.Count + 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 4 + rets.Count + 1].Contents[0].Rotation = 0;
                    tb.Cells[6, 4 + rets.Count + 1].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 6, 4 + rets.Count + 1, 7, 4 + rets.Count + 1));
                    if (totalUb != 0)
                    {
                        tb.Cells[8, 4 + rets.Count].TextString = totalUblot.ToString();
                        tb.Cells[8, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[8, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[8, 4 + rets.Count].Contents[0].Rotation = 0;
                        tb.Cells[8, 4 + rets.Count].Contents[0].TextStyleId = id;
                        //tb.MergeCells(CellRange.Create(tb, 8, 4 + rets.Count, 8, 4 + rets.Count + 1));
                        tb.Cells[8, 4 + rets.Count + 1].TextString = totalUblot.ToString();
                        tb.Cells[8, 4 + rets.Count + 1].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[8, 4 + rets.Count + 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[8, 4 + rets.Count + 1].Contents[0].Rotation = 0;
                        tb.Cells[8, 4 + rets.Count + 1].Contents[0].TextStyleId = id;
                    }
                }
                else
                {
                    double totalweight = 0;
                    int totalUblot = 0;
                    for (int n = 0; n < dicList[0].Count; n++)
                    {
                        double total12weight = 0;
                        totalUblot = 0;


                        for (int i = 0; i < rets.Count; i++)
                        {
                            double weight = 0;
                            foreach (RebarBase info in dicList[i][dicList[0].Keys.ToList()[n]])
                            {
                                weight += info.TotalWeight;
                            }
                            //if (rets[i].PierNumber == "P-214")
                            //    num = 2;
                            //else
                            //    num = 1;
                            weight = weight * num;
                            tb.Cells[6 + n, 4 + i].TextString = weight.ToString("0.000"); ;
                            tb.Cells[6 + n, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                            tb.Cells[6 + n, 4 + i].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[6 + n, 4 + i].Contents[0].Rotation = 0;
                            tb.Cells[6 + n, 4 + i].Contents[0].TextStyleId = id;

                            total12weight += weight;
                            //if (rets[i].PierNumber == "P-214")
                            //    num = 2;
                            //else
                            //    num = 1;
                            tb.Cells[6 + dicList[0].Count, 4 + i].TextString = (rets[i].UAN1N2 * num).ToString();
                            tb.Cells[6 + dicList[0].Count, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                            tb.Cells[6 + dicList[0].Count, 4 + i].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[6 + dicList[0].Count, 4 + i].Contents[0].Rotation = 0;
                            tb.Cells[6 + dicList[0].Count, 4 + i].Contents[0].TextStyleId = id;

                            totalUblot += rets[i].UAN1N2 * num;
                        }

                        tb.Cells[6 + n, 4 + rets.Count].TextString = total12weight.ToString();
                        tb.Cells[6 + n, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[6 + n, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[6 + n, 4 + rets.Count].Contents[0].Rotation = 0;
                        tb.Cells[6 + n, 4 + rets.Count].Contents[0].TextStyleId = id;
                        totalweight += total12weight;
                    }

                    //tb.Cells[6, 4 + rets.Count].TextString = total12weight.ToString();
                    //tb.Cells[6, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                    //tb.Cells[6, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                    //tb.Cells[6, 4 + rets.Count].Contents[0].Rotation = 0;
                    //tb.Cells[6, 4 + rets.Count].Contents[0].TextStyleId = id;

                    //tb.Cells[7, 4 + rets.Count].TextString = total32weight.ToString();
                    //tb.Cells[7, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                    //tb.Cells[7, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                    //tb.Cells[7, 4 + rets.Count].Contents[0].Rotation = 0;
                    //tb.Cells[7, 4 + rets.Count].Contents[0].TextStyleId = id;

                    tb.Cells[6, 4 + rets.Count + 1].TextString = totalweight.ToString();
                    tb.Cells[6, 4 + rets.Count + 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 4 + rets.Count + 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 4 + rets.Count + 1].Contents[0].Rotation = 0;
                    tb.Cells[6, 4 + rets.Count + 1].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 6, 4 + rets.Count + 1, 6 + dicList[0].Count - 1, 4 + rets.Count + 1));
                    if (totalUb != 0)
                    {
                        tb.Cells[6 + dicList[0].Count, 4 + rets.Count].TextString = totalUblot.ToString();
                        tb.Cells[6 + dicList[0].Count, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[6 + dicList[0].Count, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[6 + dicList[0].Count, 4 + rets.Count].Contents[0].Rotation = 0;
                        tb.Cells[6 + dicList[0].Count, 4 + rets.Count].Contents[0].TextStyleId = id;
                        //tb.MergeCells(CellRange.Create(tb, 8, 4 + rets.Count, 8, 4 + rets.Count + 1));
                        tb.Cells[6 + dicList[0].Count, 4 + rets.Count + 1].TextString = totalUblot.ToString();
                        tb.Cells[6 + dicList[0].Count, 4 + rets.Count + 1].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[6 + dicList[0].Count, 4 + rets.Count + 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[6 + dicList[0].Count, 4 + rets.Count + 1].Contents[0].Rotation = 0;
                        tb.Cells[6 + dicList[0].Count, 4 + rets.Count + 1].Contents[0].TextStyleId = id;
                    }
                }
                //tb.MergeCells(CellRange.Create(tb, 8, 4 + rets.Count, 8, 4 + rets.Count + 1));
                for (int i = 0; i < col; ++i)
                {
                    if (i > 3 && i < col - 2)
                        tb.Columns[i].Width = 25 * scale;
                    else
                        tb.Columns[i].Width = 18 * scale;
                }

                for (int i = 0; i < row; ++i)
                {
                    tb.Rows[i].Height = 8 * scale;
                }

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                tr.Commit();
                Extents3d ex3d = new Extents3d(tb.Bounds.Value.MinPoint.Convert3D(), tb.Bounds.Value.MaxPoint.Convert3D());
                ext = ex3d.Convert2D();
                #endregion


                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                //Common.CreateLayout(db, "墩柱钢筋", ext, scale, 1,false, tkPath);
                Common.CreateLayoutNew(db, "墩柱钢筋", ext, scale, 1, -2, 0,false, tkPath);
            }


        }



        /// <summary>
        /// 批量墩柱数量比较多合并绘制
        /// </summary>
        /// <param name="db"></param>
        /// <param name="rets"></param>
        /// <param name="pierHeight"></param>
        /// <param name="startPoint"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="type"></param>
        /// <param name="title"></param>
        /// <param name="num"></param>
        public static void DrawColumnListMergeTB(Database db, List<MemberBase> rets, List<int> pierHeight,
Point3d startPoint, string txtStyle, double scale, string type = "C-PTM2-C", string title = "MAINLINE", int num = 2,string tkPath="")
        {
            List<List<MemberBase>> divDic = new List<List<MemberBase>>();
            List<List<int>> pierH = new List<List<int>>();
            CalcCloumListPage(rets, pierHeight, scale, ref divDic, ref pierH);
            Extents2d ext1 = new Extents2d(Point2d.Origin.Convert2D(0,297 * 2), Point2d.Origin.Convert2D(0, 297 * 2));
            Extents2d ext2 = new Extents2d(Point2d.Origin.Convert2D(0, 297 * 2), Point2d.Origin.Convert2D(0, 297 * 2));
            //#region 绘制表
            for (int n = 0; n < divDic.Count; n++)
            {
                if (n == 0)
                    PloterTable.DrawCListMergeTable(db, divDic[n], rets, pierH[n], ref ext1, startPoint.Convert3D(420 * n),
                                               Extensions.curFont, scale, type, false, title, num);
                else
                    PloterTable.DrawCListMergeTable(db, divDic[n], rets, pierH[n], ref ext2, startPoint.Convert3D(420 * n),
                                            Extensions.curFont, scale, type, true, title, num);
            }


            //Common.CreateLayout(db, "墩柱钢筋", ext1, ext2, scale, 1,false, tkPath);
            Common.CreateCLayout(db, "墩柱钢筋", ext1, ext2, scale, 1, -2, false, tkPath);
        }

        public static void DrawCListMergeTable(Database db, List<MemberBase> rets, List<MemberBase> retsT, List<int> pierHeight, ref Extents2d ext,
Point3d startPoint, string txtStyle, double scale, string type = "C-PTM2-C", bool isDrawTotal = true, string title = "MAINLINE", int num = 2)
        {

            Table tb = new Table();
            List<Dictionary<eDB, List<RebarBase>>> dicList = new List<Dictionary<eDB, List<RebarBase>>>();
            int ubolt_row = 0;
            foreach (MemberBase ret in rets)
            {
                if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
                {
                    throw new Exception("数据异常");
                }

                Dictionary<eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

                #region 统计合并数据
                foreach (RebarBase item in ret.RebarList)
                {
                    if (dic.Count == 0)
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                    else
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        dic.TryGetValue(item.Diameter, out items);
                        if (items == null || items.Count == 0)
                        {
                            items = new List<RebarBase>();
                        }
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                }
                dicList.Add(dic);

            
                #endregion

            }


            //#region 设置表格长宽

            int row = 1 + 4 + 4;
           
            int col = 6 + rets.Count;
            if (!isDrawTotal)
                col = 4 + rets.Count;
            tb.SetSize(row, col);
            tb.Position = startPoint;
            tb.GenerateLayout();
            //#endregion

            #region 设置表头
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                tb.Cells[0, 0].TextString = String.Format("COLUMN LIST AND QUANTITIES FOR {0} TO {1} OF " + title + "({2} COLUMNS)",
                      retsT[0].PierNumber, retsT[rets.Count - 1].PierNumber, retsT.Count * num);

                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;

                tb.Cells[1, 0].TextString = "Items";
                tb.Cells[1, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 0].Contents[0].Rotation = 0;
                tb.Cells[1, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 0, 4, 2));

                tb.Cells[1, 3].TextString = "unit";
                tb.Cells[1, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 3].Contents[0].Rotation = 0;
                tb.Cells[1, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 3, 4, 3));

                tb.Cells[1, 4].TextString = "Column";
                tb.Cells[1, 4].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 4].Contents[0].Rotation = 0;
                tb.Cells[1, 4].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 4, 1, 4 + rets.Count - 1));

                for (int i = 0; i < rets.Count; i++)
                {
                    tb.Cells[2, 4 + i].TextString = rets[i].PierNumber;
                    tb.Cells[2, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[2, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[2, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[2, 4 + i].Contents[0].TextStyleId = id;

                    tb.Cells[3, 4 + i].TextString = type;
                    tb.Cells[3, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[3, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[3, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[3, 4 + i].Contents[0].TextStyleId = id;

                    tb.Cells[4, 4 + i].TextString = "Height=" + pierHeight[i] * 0.001 + "m";
                    tb.Cells[4, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[4, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[4, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[4, 4 + i].Contents[0].TextStyleId = id;
                }





                tb.Cells[5, 0].TextString = "Column Qty.";
                tb.Cells[5, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[5, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[5, 0].Contents[0].Rotation = 0;
                tb.Cells[5, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 5, 0, 5, 2));

                tb.Cells[5, 3].TextString = "Number";
                tb.Cells[5, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[5, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[5, 3].Contents[0].Rotation = 0;
                tb.Cells[5, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 5, 3, 5, 3));

                for (int i = 0; i < rets.Count; i++)
                {
                    tb.Cells[5, 4 + i].TextString = num.ToString();
                    tb.Cells[5, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[5, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[5, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[5, 4 + i].Contents[0].TextStyleId = id;
                }



                tb.Cells[6, 0].TextString = "Material";
                tb.Cells[6, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[6, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[6, 0].Contents[0].Rotation = 0;
                tb.Cells[6, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 6, 0, 8, 0));

                tb.Cells[6, 1].TextString = "Bars";
                tb.Cells[6, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[6, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[6, 1].Contents[0].Rotation = 0;
                tb.Cells[6, 1].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 6, 1, 7, 1));

                tb.Cells[6, 2].TextString = "DB12";
                tb.Cells[6, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[6, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[6, 2].Contents[0].Rotation = 0;
                tb.Cells[6, 2].Contents[0].TextStyleId = id;

                tb.Cells[7, 2].TextString = "DB32";
                tb.Cells[7, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[7, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[7, 2].Contents[0].Rotation = 0;
                tb.Cells[7, 2].Contents[0].TextStyleId = id;

                tb.Cells[6, 3].TextString = "kg";
                tb.Cells[6, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[6, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[6, 3].Contents[0].Rotation = 0;
                tb.Cells[6, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 6, 3, 7, 3));

                tb.Cells[8, 1].TextString = "U-bolt A";
                tb.Cells[8, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[8, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[8, 1].Contents[0].Rotation = 0;
                tb.Cells[8, 1].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 8, 1, 8, 2));

                tb.Cells[8, 3].TextString = "Number";
                tb.Cells[8, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[8, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[8, 3].Contents[0].Rotation = 0;
                tb.Cells[8, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 8, 3, 8, 3));
                double total12weight = 0;
                double total32weight = 0;
                int totalUblot = 0;
                for (int i = 0; i < rets.Count; i++)
                {
                    double weight = 0;
                    foreach (RebarBase info in dicList[i][eDB.DB12])
                    {
                        weight += info.TotalWeight;
                    }
                    weight = weight * num;
                    tb.Cells[6, 4 + i].TextString = weight.ToString("0.000"); ;
                    tb.Cells[6, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[6, 4 + i].Contents[0].TextStyleId = id;

                    //total12weight += weight;

                    weight = 0;
                    foreach (RebarBase info in dicList[i][eDB.DB32])
                    {
                        weight += info.TotalWeight;
                    }
                    weight = weight * num;
                    tb.Cells[7, 4 + i].TextString = weight.ToString("0.000"); ;
                    tb.Cells[7, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[7, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[7, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[7, 4 + i].Contents[0].TextStyleId = id;

                    //total32weight += weight;

                    tb.Cells[8, 4 + i].TextString = (rets[i].UAN1N2 * num).ToString();
                    tb.Cells[8, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[8, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[8, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[8, 4 + i].Contents[0].TextStyleId = id;

                    //totalUblot += rets[i].UAN1N2 * 2;
                }

                if (isDrawTotal)
                {

                    dicList = new List<Dictionary<eDB, List<RebarBase>>>();

                    foreach (MemberBase ret in retsT)
                    {
                        if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
                        {
                            throw new Exception("数据异常");
                        }

                        Dictionary<eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

                        #region 统计合并数据
                        foreach (RebarBase item in ret.RebarList)
                        {
                            if (dic.Count == 0)
                            {
                                List<RebarBase> items = new List<RebarBase>();
                                items.Add(item);
                                dic[item.Diameter] = items;
                            }
                            else
                            {
                                List<RebarBase> items = new List<RebarBase>();
                                dic.TryGetValue(item.Diameter, out items);
                                if (items == null || items.Count == 0)
                                {
                                    items = new List<RebarBase>();
                                }
                                items.Add(item);
                                dic[item.Diameter] = items;
                            }
                        }
                        dicList.Add(dic);
                        #endregion

                    }
                    for (int i = 0; i < retsT.Count; i++)
                    {
                        double weight = 0;
                        foreach (RebarBase info in dicList[i][eDB.DB12])
                        {
                            weight += info.TotalWeight;
                        }
                        weight = weight * num;
                        total12weight += weight;

                        weight = 0;
                        foreach (RebarBase info in dicList[i][eDB.DB32])
                        {
                            weight += info.TotalWeight;
                        }
                        weight = weight * num;
                        total32weight += weight;

                        totalUblot += retsT[i].UAN1N2 * num;
                    }
                    tb.Cells[1, 4 + rets.Count].TextString = "Total";
                    tb.Cells[1, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 4 + rets.Count].Contents[0].Rotation = 0;
                    tb.Cells[1, 4 + rets.Count].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 1, 4 + rets.Count, 4, 4 + rets.Count + 1));

                    tb.Cells[5, 4 + rets.Count].TextString = (2 * retsT.Count).ToString();
                    tb.Cells[5, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[5, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[5, 4 + rets.Count].Contents[0].Rotation = 0;
                    tb.Cells[5, 4 + rets.Count].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 5, 4 + rets.Count, 5, 4 + rets.Count + 1));



                    tb.Cells[6, 4 + rets.Count].TextString = total12weight.ToString();
                    tb.Cells[6, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 4 + rets.Count].Contents[0].Rotation = 0;
                    tb.Cells[6, 4 + rets.Count].Contents[0].TextStyleId = id;

                    tb.Cells[7, 4 + rets.Count].TextString = total32weight.ToString();
                    tb.Cells[7, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[7, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[7, 4 + rets.Count].Contents[0].Rotation = 0;
                    tb.Cells[7, 4 + rets.Count].Contents[0].TextStyleId = id;

                    tb.Cells[6, 4 + rets.Count + 1].TextString = (total12weight + total32weight).ToString();
                    tb.Cells[6, 4 + rets.Count + 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 4 + rets.Count + 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 4 + rets.Count + 1].Contents[0].Rotation = 0;
                    tb.Cells[6, 4 + rets.Count + 1].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 6, 4 + rets.Count + 1, 7, 4 + rets.Count + 1));

                    tb.Cells[8, 4 + rets.Count].TextString = totalUblot.ToString();
                    tb.Cells[8, 4 + rets.Count].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[8, 4 + rets.Count].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[8, 4 + rets.Count].Contents[0].Rotation = 0;
                    tb.Cells[8, 4 + rets.Count].Contents[0].TextStyleId = id;
                    //tb.MergeCells(CellRange.Create(tb, 8, 4 + rets.Count, 8, 4 + rets.Count + 1));
                    tb.Cells[8, 4 + rets.Count + 1].TextString = totalUblot.ToString();
                    tb.Cells[8, 4 + rets.Count + 1].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[8, 4 + rets.Count + 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[8, 4 + rets.Count + 1].Contents[0].Rotation = 0;
                    tb.Cells[8, 4 + rets.Count + 1].Contents[0].TextStyleId = id;
                }
                //tb.MergeCells(CellRange.Create(tb, 8, 4 + rets.Count, 8, 4 + rets.Count + 1));
                for (int i = 0; i < col; ++i)
                {
                    if (isDrawTotal)
                    {
                        if (i > 3 && i < col - 2)
                            tb.Columns[i].Width = 25 * scale;
                        else
                            tb.Columns[i].Width = 18 * scale;
                    }
                    else
                    {
                        if (i > 3)
                            tb.Columns[i].Width = 25 * scale;
                        else
                            tb.Columns[i].Width = 18 * scale;
                    }
                }

                for (int i = 0; i < row; ++i)
                {
                    tb.Rows[i].Height = 8 * scale;
                }

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                tr.Commit();
                Extents3d ex3d = new Extents3d(tb.Bounds.Value.MinPoint.Convert3D(), tb.Bounds.Value.MaxPoint.Convert3D());
                ext = ex3d.Convert2D();
                #endregion


                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

            }


        }

        #endregion

        #region 分页及其他
        /// <summary>
        /// 墩柱分页
        /// </summary>
        /// <param name="rets"></param>
        /// <param name="pierHeight"></param>
        /// <param name="scale"></param>
        /// <param name="divDic"></param>
        /// <param name="pierH"></param>
        public static void CalcCloumListPage(List<MemberBase> rets, List<int> pierHeight, double scale, ref List<List<MemberBase>> divDic, ref List<List<int>> pierH)
        {
            List<MemberBase> div = new List<MemberBase>();
            List<int> divH = new List<int>();
            int pagNum = rets.Count / 2 + 2;
            if (rets.Count % 2 == 0)
                pagNum = rets.Count / 2 + 1;
            int page = 0;
            for (int i = 0; i < rets.Count; i++)
            {
                if (page != i / pagNum)
                {
                    divDic.Add(div);
                    pierH.Add(divH);
                    div = new List<MemberBase>();
                    divH = new List<int>();
                    page++;
                }
                //同样的直径和类型合并
                int p = i / pagNum;
                if (i <= (p + 1) * pagNum)
                {
                    div.Add(rets[i]);
                    divH.Add(pierHeight[i]);
                }

            }
            divDic.Add(div);
            pierH.Add(divH);

        }

        /// <summary>
        /// 墩柱U-bolt处理
        /// </summary>
        /// <param name="tb"></param>
        /// <param name="ret"></param>
        /// <param name="id"></param>
        /// <param name="num"></param>
        /// <param name="rowNumIndex"></param>
        /// <param name="scale"></param>
        public static void LoadColunmOtherTableData(Table tb, MemberBase ret, ObjectId id, int num, int rowNumIndex, double scale)
        {
            if (tb == null)
            {
                throw new Exception("表格异常");
            }

            // 第一列
            tb.Cells[rowNumIndex, 0].TextString = "Others";
            tb.Cells[rowNumIndex, 0].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 0].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 0].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 0].Contents[0].TextStyleId = id;

            // 第一列
            string Name = "";


            Name = "M10/U-bolt A(32/32)";

            tb.Cells[rowNumIndex, 1].TextString = Name;
            tb.Cells[rowNumIndex, 1].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 1].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 1].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 1].Contents[0].TextStyleId = id;

            tb.Cells[rowNumIndex, 2].TextString = "number";
            tb.Cells[rowNumIndex, 2].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 2].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 2].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 2].Contents[0].TextStyleId = id;

            tb.Cells[rowNumIndex, 3].TextString = num.ToString();
            tb.Cells[rowNumIndex, 3].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 3].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 3].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 3].Contents[0].TextStyleId = id;
        }
        /// <summary>
        /// 承台U-bolt处理
        /// </summary>
        /// <param name="tb"></param>
        /// <param name="ret"></param>
        /// <param name="id"></param>
        /// <param name="Name"></param>
        /// <param name="num"></param>
        /// <param name="rowNumIndex"></param>
        /// <param name="scale"></param>
        public static void LoadBeamOtherTableData(Table tb, MemberBase ret, ObjectId id, string Name, int num, int rowNumIndex, double scale)
        {
            if (tb == null)
            {
                throw new Exception("表格异常");
            }

            // 第一列
            //tb.Cells[rowNumIndex, 0].TextString = "Others";
            //tb.Cells[rowNumIndex, 0].Contents[0].TextHeight = 2 * scale;
            //tb.Cells[rowNumIndex, 0].Alignment = CellAlignment.MiddleCenter;
            //tb.Cells[rowNumIndex, 0].Contents[0].Rotation = 0;
            //tb.Cells[rowNumIndex, 0].Contents[0].TextStyleId = id;

            // 第一列


            tb.Cells[rowNumIndex, 0].TextString = Name;
            tb.Cells[rowNumIndex, 0].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 0].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 0].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 0].Contents[0].TextStyleId = id;
            tb.MergeCells(CellRange.Create(tb, rowNumIndex, 0, rowNumIndex, 1));

            tb.Cells[rowNumIndex, 2].TextString = "number";
            tb.Cells[rowNumIndex, 2].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 2].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 2].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 2].Contents[0].TextStyleId = id;

            tb.Cells[rowNumIndex, 3].TextString = num.ToString();
            tb.Cells[rowNumIndex, 3].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 3].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 3].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 3].Contents[0].TextStyleId = id;
        }

        /// <summary>
        ///  墩柱合并U-bolt处理
        /// </summary>
        /// <param name="tb"></param>
        /// <param name="ret"></param>
        /// <param name="id"></param>
        /// <param name="uBolt"></param>
        /// <param name="num"></param>
        /// <param name="rowNumIndex"></param>
        /// <param name="scale"></param>
        public static void LoadOtherTableData(Table tb, MemberBase ret, ObjectId id, string uBolt, int num, int rowNumIndex, double scale)
        {
            if (tb == null)
            {
                throw new Exception("表格异常");
            }

            // 第一列
            tb.Cells[rowNumIndex, 0].TextString = "Others";
            tb.Cells[rowNumIndex, 0].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 0].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 0].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 0].Contents[0].TextStyleId = id;

            // 第一列
            string Name = "";
            string sBegin = "";
            string sEnd = "";
            int beginIndex = 0;
            int endIndex = 0;
            beginIndex = int.Parse(uBolt.Substring(3, 1));
            endIndex = int.Parse(uBolt.Substring(5, 1));
            if (uBolt.ToLower().Contains("a"))
            {
                Name = "U-bolt A";

                RebarBase beginItem = ret.RebarList.Find(x => (x.CBarMark.ToLower() == "a" && x.MBarMark == beginIndex)||(x.CBarMark.ToLower() == ""&&x.MBarMark == beginIndex));
                RebarBase endItem = ret.RebarList.Find(x => (x.CBarMark.ToLower() == "a" && x.MBarMark == endIndex)||(x.CBarMark.ToLower() == "" && x.MBarMark == endIndex));
                sBegin = beginItem.Diameter.ToString().Substring(2, 2);
                sEnd = endItem.Diameter.ToString().Substring(2, 2);
            }
            else if (uBolt.ToLower().Contains("b"))
            {
                Name = "U-bolt B";
                RebarBase beginItem = ret.RebarList.Find(x => (x.CBarMark.ToLower() == "b" && x.MBarMark == beginIndex)|| (x.CBarMark.ToLower() == "" && x.MBarMark == beginIndex));
                RebarBase endItem = ret.RebarList.Find(x => (x.CBarMark.ToLower() == "b" && x.MBarMark == endIndex)||(x.CBarMark.ToLower() == "" && x.MBarMark == endIndex));
                sBegin = beginItem.Diameter.ToString().Substring(2, 2);
                sEnd = endItem.Diameter.ToString().Substring(2, 2);
            }

            Name = string.Format("{0}({1}/{2})", Name, sBegin, sEnd);
            tb.Cells[rowNumIndex, 1].TextString = Name;
            tb.Cells[rowNumIndex, 1].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 1].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 1].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 1].Contents[0].TextStyleId = id;

            tb.Cells[rowNumIndex, 2].TextString = "number";
            tb.Cells[rowNumIndex, 2].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 2].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 2].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 2].Contents[0].TextStyleId = id;

            tb.Cells[rowNumIndex, 3].TextString = num.ToString();
            tb.Cells[rowNumIndex, 3].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 3].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 3].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 3].Contents[0].TextStyleId = id;
        }

        /// <summary>
        /// 绘制干线数据表
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="headName"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        public static Table DrawFootingMainLineTable(Database db, ref Extents2d ext, Point3d startPoint, List<string> headName,
            string txtStyle, double scale)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                #region 读取excel数据
                OpenFileDialog openFile = new OpenFileDialog();
                openFile.Filter = "Excel(*.xlsx)|*.xlsx|Excel(*.xls)|*.xls";
                openFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                openFile.Multiselect = false;
                if (openFile.ShowDialog() == DialogResult.Cancel) return null;
                var excelFilePath = openFile.FileName;

                Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
                Microsoft.Office.Interop.Excel.Sheets sheets;
                object oMissiong = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Excel.Workbook workbook = null;
                System.Data.DataTable dt = new System.Data.DataTable();
                if (app == null) return null;
                workbook = app.Workbooks.Open(excelFilePath, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong,
                    oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong);
                sheets = workbook.Worksheets;

                //将数据读入到DataTable中
                Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);//读取第一张表  
                if (worksheet == null) return null;

                int iRowCount = worksheet.UsedRange.Rows.Count;
                int iColCount = worksheet.UsedRange.Columns.Count;

                List<PierFootData> list = new List<PierFootData>();
                for (int i = 2; i <= iRowCount; ++i)
                {
                    PierFootData data = new PierFootData();
                    for (int j = 1; j <= iColCount; ++j)
                    {
                        if (worksheet.Cells[i, j].Text == null)
                        {
                            continue;
                        }
                        if (j == 1)
                        {
                            data.PierNo = worksheet.Cells[i, j].Text.ToString();
                        }
                        else if (j == 2)
                        {
                            data.Station = worksheet.Cells[i, j].Text.ToString();
                        }
                        else if (j == 3)
                        {
                            data.FootType = worksheet.Cells[i, j].Text.ToString();
                        }
                        else if (j == 4)
                        {
                            data.ColumnType = worksheet.Cells[i, j].Text.ToString();
                        }
                        else if (j == 5)
                        {
                            data.ColumnHeight = worksheet.Cells[i, j].Text.ToString();
                        }
                        else if (j == 6)
                        {
                            data.TopFoot = double.Parse(worksheet.Cells[i, j].Text.ToString());
                        }
                        else if (j == 7)
                        {
                            data.H = double.Parse(worksheet.Cells[i, j].Text.ToString());
                        }
                        else if (j == 8)
                        {
                            data.para1 = double.Parse(worksheet.Cells[i, j].Text.ToString());
                        }
                        else if (j == 9)
                        {
                            data.para2 = double.Parse(worksheet.Cells[i, j].Text.ToString());
                        }
                        else if (j == 10)
                        {
                            data.para3 = double.Parse(worksheet.Cells[i, j].Text.ToString());
                        }
                        else if (j == 11)
                        {
                            data.FootingType = double.Parse(worksheet.Cells[i, j].Text.ToString());
                        }
                    }
                    list.Add(data);
                }
                #endregion

                #region 获取Coordinates数据
                string pierNo = "";
                double A = 0;
                double B = 0;
                double L = 0;
                // F-L
                for (int i = 0; i < list.Count; ++i)
                {
                    A = list[i].para1;
                    B = list[i].para3;
                    L = list[i].para2;
                    if (!string.IsNullOrEmpty(list[i].PierNo))
                    {
                        pierNo = list[i].PierNo;
                        if (list[i].FootingType == 0)
                        {
                            // F-L
                        }
                    }
                    else
                    {
                        if (list[i].FootingType == 1)
                        {
                            // F-R
                        }
                    }
                }
                // F-R

                #endregion

                Table tb = new Table();
                int row = list.Count + 2;
                int col = 12;
                tb.SetSize(row, col);
                tb.Position = startPoint;
                tb.GenerateLayout();

                #region 设置表头
                for (int i = 0; i < col - 1; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i];
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }

                tb.Cells[1, 10].TextString = "N.";
                tb.Cells[1, 10].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 10].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 10].Contents[0].Rotation = 0;
                tb.Cells[1, 10].Contents[0].TextStyleId = id;

                tb.Cells[1, 11].TextString = "E.";
                tb.Cells[1, 11].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 11].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 11].Contents[0].Rotation = 0;
                tb.Cells[1, 11].Contents[0].TextStyleId = id;
                #endregion

                #region 设置表格数据
                for (int i = 0; i < list.Count; ++i)
                {
                    // mainline
                    tb.Cells[i + 2, 0].TextString = "MAINLINE";
                    tb.Cells[i + 2, 0].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i + 2, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i + 2, 0].Contents[0].Rotation = 0;
                    tb.Cells[i + 2, 0].Contents[0].TextStyleId = id;

                    // pier N.
                    tb.Cells[i + 2, 1].TextString = list[i].PierNo;
                    tb.Cells[i + 2, 1].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i + 2, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i + 2, 1].Contents[0].Rotation = 0;
                    tb.Cells[i + 2, 1].Contents[0].TextStyleId = id;

                    // station
                    string station = list[i].Station;
                    string str1 = list[i].Station.Substring(0, station.Length - 3);
                    str1 = str1.Trim();
                    string str2 = list[i].Station.Substring(station.Length - 3, 3);
                    str2 = str2.Trim();
                    if (string.IsNullOrEmpty(str1) || string.IsNullOrEmpty(str2))
                    {
                        tb.Cells[i + 2, 2].TextString = "-";
                    }
                    else
                    {
                        double dbPara = double.Parse(str2);
                        tb.Cells[i + 2, 2].TextString = string.Format("{0}-{1:N3}", str1, dbPara);
                    }

                    tb.Cells[i + 2, 2].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i + 2, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i + 2, 2].Contents[0].Rotation = 0;
                    tb.Cells[i + 2, 2].Contents[0].TextStyleId = id;

                    // footing N.
                    if (list[i].FootingType == 0)
                    {
                        // 左
                        tb.Cells[i + 2, 3].TextString = "F-L";
                        tb.Cells[i + 2, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i + 2, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i + 2, 3].Contents[0].Rotation = 0;
                        tb.Cells[i + 2, 3].Contents[0].TextStyleId = id;
                    }
                    else if (list[i].FootingType == 1)
                    {
                        // 右
                        tb.Cells[i + 2, 3].TextString = "F-R";
                        tb.Cells[i + 2, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i + 2, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i + 2, 3].Contents[0].Rotation = 0;
                        tb.Cells[i + 2, 3].Contents[0].TextStyleId = id;
                    }

                    // type of footing
                    tb.Cells[i + 2, 4].TextString = list[i].FootType;
                    tb.Cells[i + 2, 4].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i + 2, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i + 2, 4].Contents[0].Rotation = 0;
                    tb.Cells[i + 2, 4].Contents[0].TextStyleId = id;

                    // type of column
                    tb.Cells[i + 2, 5].TextString = list[i].ColumnType;
                    tb.Cells[i + 2, 5].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i + 2, 5].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i + 2, 5].Contents[0].Rotation = 0;
                    tb.Cells[i + 2, 5].Contents[0].TextStyleId = id;

                    // column height
                    tb.Cells[i + 2, 6].TextString = list[i].ColumnHeight.ToString();
                    tb.Cells[i + 2, 6].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i + 2, 6].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i + 2, 6].Contents[0].Rotation = 0;
                    tb.Cells[i + 2, 6].Contents[0].TextStyleId = id;

                    // elevation at top of footing 
                    tb.Cells[i + 2, 7].TextString = string.Format("{0:N3}", list[i].TopFoot);
                    tb.Cells[i + 2, 7].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i + 2, 7].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i + 2, 7].Contents[0].Rotation = 0;
                    tb.Cells[i + 2, 7].Contents[0].TextStyleId = id;

                    // elevation at bottom of footing 
                    tb.Cells[i + 2, 8].TextString = string.Format("{0:N3}", list[i].TopFoot - list[i].H);
                    tb.Cells[i + 2, 8].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i + 2, 8].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i + 2, 8].Contents[0].Rotation = 0;
                    tb.Cells[i + 2, 8].Contents[0].TextStyleId = id;

                    // point N.
                    tb.Cells[i + 2, 9].TextString = string.Format("{0:N3}", list[i].para2);
                    tb.Cells[i + 2, 9].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i + 2, 9].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i + 2, 9].Contents[0].Rotation = 0;
                    tb.Cells[i + 2, 9].Contents[0].TextStyleId = id;

                    // Coordinates N.
                    tb.Cells[i + 2, 10].TextString = string.Format("{0:N3}", list[i].para2); ;
                    tb.Cells[i + 2, 10].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i + 2, 10].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i + 2, 10].Contents[0].Rotation = 0;
                    tb.Cells[i + 2, 10].Contents[0].TextStyleId = id;

                    // Coordinates E.
                    tb.Cells[i + 2, 10].TextString = string.Format("{0:N3}", list[i].para3); ;
                    tb.Cells[i + 2, 10].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[i + 2, 10].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i + 2, 10].Contents[0].Rotation = 0;
                    tb.Cells[i + 2, 10].Contents[0].TextStyleId = id;
                }
                #endregion

                #region 设置表格行高和列宽
                for (int i = 0; i < tb.Rows.Count; ++i)
                {
                    tb.Rows[i].Height = 5.5 * scale;
                }

                for (int i = 0; i < tb.Columns.Count; ++i)
                {
                    if (i == 0 || i == 1 || i == 2 || i == 3
                        || i == 9)
                    {
                        tb.Columns[i].Width = 20 * scale;
                    }
                    else if (i == 7 || i == 8)
                    {
                        tb.Columns[i].Width = 35 * scale;
                    }
                    else
                    {
                        tb.Columns[i].Width = 25 * scale;
                    }
                }
                #endregion

                #region 合并表格
                List<CellRange> cellList = new List<CellRange>();

                CellRange range1 = CellRange.Create(tb, 2, 0, tb.Rows.Count - 1, 0);
                cellList.Add(range1);

                CellRange range2 = CellRange.Create(tb, 0, 0, 1, 0);
                cellList.Add(range2);

                CellRange range3 = CellRange.Create(tb, 0, 1, 1, 1);
                cellList.Add(range3);

                CellRange range4 = CellRange.Create(tb, 0, 2, 1, 2);
                cellList.Add(range4);

                CellRange range5 = CellRange.Create(tb, 0, 3, 1, 3);
                cellList.Add(range5);

                CellRange range6 = CellRange.Create(tb, 0, 4, 1, 4);
                cellList.Add(range6);

                CellRange range7 = CellRange.Create(tb, 0, 5, 1, 5);
                cellList.Add(range7);

                CellRange range8 = CellRange.Create(tb, 0, 6, 1, 6);
                cellList.Add(range8);

                CellRange range9 = CellRange.Create(tb, 0, 7, 1, 7);
                cellList.Add(range9);

                CellRange range10 = CellRange.Create(tb, 0, 8, 1, 8);
                cellList.Add(range10);

                CellRange range11 = CellRange.Create(tb, 0, 9, 1, 9);
                cellList.Add(range11);

                CellRange range12 = CellRange.Create(tb, 0, 10, 0, 11);
                cellList.Add(range12);

                foreach (CellRange range in cellList)
                {
                    tb.MergeCells(range);
                }
                #endregion

                tb.SetSize(20, col);
                tb.Position = startPoint;
                tb.GenerateLayout();

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                tr.Commit();

                return tb;
            }
        }
        #endregion

        #region 表格绘制
        /// <summary>
        /// 绘制表
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="headName"></param>
        /// <param name="rowNum"></param>
        /// <param name="colNum"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="tbValue"></param>
        /// <param name="typeName"></param>
        /// <param name="structureName"></param>
        /// <param name="type"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>
        public static Table DrawColumnTable(Database db, ref Extents2d ext, Point3d startPoint,
      int rowNum, string txtStyle, double scale, RebarCollection tbValue, string typeName, string structureName,
      string pierHeight, string pierName, FDEE.Model.eSubType type, int pageCount = 0, string title = "MAINLINE")
        {
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("E\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");
            tbH = 0;
            int cuRCount = 0;//当前页行高小于块高度的数量
            int curAllRow = 0;//当前页行数
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                //int rowNum = tbValue.Count + 2;
                // 创建table 
                startPoint = startPoint.Convert3D(420 * pageCount);
                Table tb = new Table();
                int colNum = headName.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 第一页
                #region 第一行 标题
                if (pierName.Contains("P-06") || pierName.Contains("P-07") || pierName.Contains("P-08"))
                {
                    if (structureName.ToString().Contains("PE"))
                    {
                        structureName = structureName.Substring(0, structureName.Length - 1) + "-" + structureName.Substring(structureName.Length - 1);
                        structureName = structureName + type.ToString().Replace("M", "*");
                    }
                    else
                    {
                        if (structureName.ToString().Contains("PL"))
                        {
                            structureName = structureName.Substring(0, structureName.Length - 1) + "-" + structureName.Substring(structureName.Length - 1);
                        }
                        else
                            structureName = structureName + "-" + type.ToString().Replace("M", "*");
                    }
                    tb.Cells[0, 0].TextString = String.Format("BAR LIST OF COLUMN {0}{1}{2} FOR {3} OF RAMP BANANI EX-1 (COLUMN HEIGHT={4}M)",
                                   "\"", structureName, "\"", pierName, pierHeight);
                }
                else if (pierName.Contains("RP11") || pierName.Contains("RP12") || pierName.Contains("RP13") || pierName.Contains("RP14")
                   || pierName.Contains("RP17") || pierName.Contains("RP18") || pierName.Contains("RP19") || pierName.Contains("RP20") || pierName.Contains("RP21"))
                {
                    if (structureName.ToString().Contains("PE"))
                    {
                        structureName = structureName.Substring(0, structureName.Length - 1) + "-" + structureName.Substring(structureName.Length - 1);
                        structureName = structureName + type.ToString().Replace("M", "*");
                    }
                    else
                    {
                        if (structureName.ToString().Contains("PL"))
                        {
                            structureName = structureName.Substring(0, structureName.Length - 1) + "-" + structureName.Substring(structureName.Length - 1);
                        }
                        else
                            structureName = structureName + "-" + type.ToString().Replace("M", "*");
                    }
                    tb.Cells[0, 0].TextString = String.Format("BAR LIST OF COLUMN {0}{1}{2} FOR {3} OF RAMP BANANI EX-2 (COLUMN HEIGHT={4}M)",
                                   "\"", structureName, "\"", pierName, pierHeight);
                }
                else if (pierName.Contains("PR-01") || pierName.Contains("PR-02") || pierName.Contains("PR-03") || pierName.Contains("PR-04") || pierName.Contains("PR-05") || pierName.Contains("PR-06")
                       || pierName.Contains("PR-07") || pierName.Contains("PR-08") || pierName.Contains("PR-09") || pierName.Contains("PR-10") || pierName.Contains("PR-11") || pierName.Contains("PR-12"))

                {
                    if (structureName.ToString().Contains("PE"))
                    {
                        structureName = structureName.Substring(0, structureName.Length - 1) + "-" + structureName.Substring(structureName.Length - 1);
                        structureName = structureName + type.ToString().Replace("M", "*");
                    }
                    else
                    {
                        if (structureName.ToString().Contains("PL"))
                        {
                            structureName = structureName.Substring(0, structureName.Length - 1) + "-" + structureName.Substring(structureName.Length - 1);
                        }
                        else
                            structureName = structureName + "-" + type.ToString().Replace("M", "*");
                    }
                    tb.Cells[0, 0].TextString = String.Format("BAR LIST OF COLUMN {0}{1}{2} FOR {3} OF " + title + "(COLUMN HEIGHT={4}M)",
                                   "\"", structureName, "\"", pierName, pierHeight);

                }
                else
                {
                    if (!structureName.ToString().Contains("PL"))
                    {
                        structureName = structureName + "-" + type.ToString().Replace("M", "*");
                    }
                    tb.Cells[0, 0].TextString = String.Format("BAR LIST OF COLUMN {0}{1}{2} FOR {3} OF " + title + "(COLUMN HEIGHT={4}M)",
                        "\"", structureName, "\"", pierName, pierHeight);
                }
                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                #endregion
                tb.Rows[0].Height = 9 * scale;

                #region 第二行 表格标题
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                #endregion

                tb.Rows[1].Height = 16 * scale;

                #region 设置表格值
                if (tbValue.Count > 0)
                {
                    for (int m = 0; m < tbValue.Count; m++)
                    {
                        try
                        {
                            //
                            string value = "";
                            int n = 0;
                            value = tbValue[m].MBarMark.ToString();
                            if (typeName.Contains("PME4-2C"))
                            {
                                if (value == "2" || value == "3")
                                {
                                    if (tbValue[m].SBarMark != 0)
                                        value = tbValue[m].MBarMark.ToString() + tbValue[m].CBarMark+ "." + tbValue[m].SBarMark.ToString();
                                    else
                                        value = tbValue[m].MBarMark.ToString() + tbValue[m].CBarMark;
                                }
                                else
                                {
                                    if (tbValue[m].SBarMark != 0)
                                        value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                                    else
                                        value = tbValue[m].MBarMark.ToString() + tbValue[m].CBarMark;
                                }
                            }
                            else
                            {
                                if (tbValue[m].SBarMark != 0)
                                    value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                                else
                                    value = tbValue[m].MBarMark.ToString() + tbValue[m].CBarMark;
                            }
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            n++;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //Formula
                            n = n + 2;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //R
                            n++;
                            value = "";
                            if (tbValue[m].R != 0)
                                value = tbValue[m].R.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //d
                            n++;
                            value = "";
                            if (tbValue[m].Diameter != 0)
                            {
                                value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                            }
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //r
                            n++;
                            value = "";
                            if (tbValue[m].r != 0)
                                value = tbValue[m].r.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //h
                            n++;
                            value = "";
                            if (tbValue[m].h != 0)
                                value = tbValue[m].h.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //n
                            n++;
                            value = "";
                            if (tbValue[m].n != 0)
                                value = tbValue[m].n.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Lx
                            n++;
                            value = "";
                            if (tbValue[m].Lx != 0)
                                value = tbValue[m].Lx.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //A
                            n++;
                            value = "";
                            if (tbValue[m].A != 0)
                                value = tbValue[m].A.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //B
                            n++;
                            value = "";
                            if (tbValue[m].B != 0)
                                value = tbValue[m].B.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //C
                            n++;
                            value = "";
                            if (tbValue[m].C != 0)
                                value = tbValue[m].C.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //D
                            n++;
                            value = "";
                            if (tbValue[m].D != 0)
                                value = tbValue[m].D.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }
                            //E
                            n++;
                            value = "";
                            if (tbValue[m].E != 0)
                                value = tbValue[m].E.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }
                            //Quantity
                            n++;
                            value = "";
                            if (tbValue[m].Quantity != 0)
                                value = tbValue[m].Quantity.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Length
                            n++;
                            value = "";
                            if (tbValue[m].Length != 0)
                                value = tbValue[m].Length.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value)); //获取i行j列数据
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalLength
                            n++;
                            value = "";
                            if (tbValue[m].TotalLength != 0)
                                value = tbValue[m].TotalLength.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //UnitWeight
                            n++;
                            value = "";
                            if (tbValue[m].UnitWeight != 0)
                                value = tbValue[m].UnitWeight.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalWeight
                            n++;
                            value = "";
                            if (tbValue[m].TotalWeight != 0)
                                value = tbValue[m].TotalWeight.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
                            {
                                //if(pierName=="P-294")
                                //_blcName = "MO";
                                //else
                                _blcName = "MO135_1";
                            }
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MRO"))
                                _blcName = "MRO";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MRC"))
                                _blcName = "MRC";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MRLC"))
                                _blcName = "MRLC";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MR"))
                                _blcName = "MR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MKLM"))
                                _blcName = "MKLM";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MKLBM"))
                                _blcName = "MKLBM";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MKLN"))
                                _blcName = "MKLN";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MKL"))
                                _blcName = "MKL";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MKAD1"))
                                _blcName = "MKAD1";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MKAD2"))
                                _blcName = "MKAD2";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MKAB"))
                                _blcName = "MKAB";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MKR1"))
                                _blcName = "MKR1";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MKR2"))
                                _blcName = "MKR2";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MKR"))
                                _blcName = "MKR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MK"))
                                _blcName = "MK";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MHXe"))
                                _blcName = "MHXe";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MHXA"))
                                _blcName = "MHXA";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MHXL1"))
                                _blcName = "MHXL1";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MHXL2"))
                                _blcName = "MHXL2";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MHXS"))
                                _blcName = "MHXS";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MHXT"))
                                _blcName = "MHXT";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MHX"))
                                _blcName = "MHX";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MLZ"))
                                _blcName = "MLZ";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MLSD"))
                                _blcName = "MLSD";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MLS"))
                                _blcName = "MLS";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MLL"))
                                _blcName = "MLL";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MLR"))
                                _blcName = "MLR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("ML"))
                                _blcName = "ML";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCO"))
                                _blcName = "MCO";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCC"))
                                _blcName = "MCC";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MAN"))
                                _blcName = "MAN";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MDR"))
                                _blcName = "MDR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MSZ"))
                                _blcName = "MSZ";
                            db.CopyBlockFromFile(_dwgPath, _blcName);

                            BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 16 * m + 8)), 0.8, _blcName, _dwgPath, 0);

                        }
                        catch (Exception ex)
                        { }
                    }
                }

                #endregion

                #region 表格添加数据

                #endregion

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = 4 * 3 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 16 * 3 * scale;
                    else if (i == 3)
                        tb.Columns[i].Width = 11 * 3 * scale;
                    else if (i > headName.Count - 4)
                        tb.Columns[i].Width = 9 * 3 * scale;
                    else if (i > headName.Count - 6)
                        tb.Columns[i].Width = 8 * 3 * scale;
                    else
                        tb.Columns[i].Width = 4 * 3 * scale;
                }
                #endregion

                //行高
                for (int i = 2; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 16 * scale;
                }

                #region 列单元格合并

                ////合并数据定义
                //Dictionary<int, int> dic = new Dictionary<int, int>();
                //int rowIndex = 0;
                //int num = 0;
                //string stShape = tbValue[0].ShapeConfg.ToString();//要合并的类型
                //string stDia = tbValue[0].Diameter.ToString();//要合并的钢筋直径
                //for (int i = 0; i < tbValue.Count; ++i)
                //{
                //    //同样的直径和类型合并
                //    if (tbValue[i].ShapeConfg.ToString() == stShape&& tbValue[i].Diameter.ToString() == stDia)
                //    {
                //        num++;
                //    }
                //    else
                //    {

                //        dic.Add(rowIndex, num);
                //        num = 1;
                //        rowIndex = i;
                //        //下一条要合并的直径和类型
                //        stDia = tbValue[i].Diameter.ToString();
                //        stShape = tbValue[i].ShapeConfg.ToString();
                //    }
                //    if (i == tbValue.Count - 1)
                //        dic.Add(rowIndex, num);
                //}

                // 列单元格合并
                //int topRow = 2;

                //List<CellRange> cellList = new List<CellRange>();

                //foreach (KeyValuePair<int, int> pr in dic)
                //{
                //    curAllRow += pr.Value;
                //    lastMegerHeight = pr.Value * 6.5 * scale;
                //    tb.Cells[topRow, 2].Alignment = CellAlignment.MiddleCenter;
                //    if (pr.Value < 4)
                //    {
                //        for (int i = 0; i < pr.Value; i++)
                //        {
                //            tb.Rows[topRow+i].Height = intervalHeight / pr.Value;                            
                //        }
                //        cuRCount++;
                //        curAllRow -= pr.Value;
                //        lastMegerHeight =32 * scale;

                //    }

                //    db.CopyBlockFromFile(_dwgPath, _blcName);
                //    BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8*3 * scale, -(7 * scale + 12 * scale + intervalHeight * cuRCount+ 6.5  * curAllRow - lastMegerHeight * 0.4)), 1, _blcName, _dwgPath, 0);
                //    CellRange range = CellRange.Create(tb, topRow, 2, topRow + pr.Value - 1, 2);


                //    cellList.Add(range);
                //    topRow += pr.Value;

                //}
                //foreach (CellRange range in cellList)
                //{
                //    tb.MergeCells(range);
                //}

                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                #endregion

                #region 其他页

                #endregion
                tr.Commit();
                return tb;
            }
        }


        /// <summary>
        /// 绘制盖梁表格
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="rowNum"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="tbValue"></param>
        /// <param name="typeName"></param>
        /// <param name="structureName"></param>
        /// <param name="capLength"></param>
        /// <param name="pierName"></param>
        /// <param name="type"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>
        public static Table DrawBeamTable(Database db, ref Extents2d ext, Point3d startPoint,
int rowNum, string txtStyle, double scale, RebarCollection tbValue, string typeName, string structureName,
string capLength, string pierName, FDEE.Model.eSubType type, int pageCount = 0)
        {
            if (typeName.ToString().Contains("PE") || typeName.ToString().Contains("PTE"))
            {
                typeName = typeName.ToString().Replace("C", "").Replace("A", "").Replace("B", "");
                typeName = typeName.Substring(0, typeName.Length - 1) + "-" + typeName.Substring(typeName.Length - 1);
                //if (column.Contains("RP11") || column.Contains("RP12") || column.Contains("RP13") || column.Contains("RP14"))
                //typeName = "C-" + type + eHeightTyp.ToString().Replace("1", "*");
            }
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");
            tbH = 0;
            int cuRCount = 0;//当前页行高小于块高度的数量
            int curAllRow = 0;//当前页行数
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                //int rowNum = tbValue.Count + 2;
                // 创建table 
                startPoint = startPoint.Convert3D(420 * pageCount);
                Table tb = new Table();
                int colNum = headName.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 第一页
                #region 第一行 标题
                tb.Cells[0, 0].TextString = String.Format("TABLE REINFORCEMENT BAR LIST TYPICAL CROSS BEAM PIER TYPE {0}(LENGTH={1}M)",
                     typeName.Replace("B", ""), capLength);
                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                #endregion
                tb.Rows[0].Height = 9 * scale;

                #region 第二行 表格标题
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                #endregion

                tb.Rows[1].Height = 16 * scale;

                #region 设置表格值
                if (tbValue.Count > 0)
                {
                    for (int m = 0; m < tbValue.Count; m++)
                    {
                        try
                        {
                            //
                            string value = "";
                            int n = 0;
                            value = tbValue[m].MBarMark.ToString();
                            if (tbValue[m].SBarMark != 0)
                                value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                            else
                                value = tbValue[m].MBarMark.ToString() + tbValue[m].CBarMark;
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            n++;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //Formula
                            n = n + 2;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //R
                            n++;
                            value = "";
                            if (tbValue[m].R != 0)
                                value = tbValue[m].R.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //d
                            n++;
                            value = "";
                            if (tbValue[m].Diameter != 0)
                            {
                                value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                            }
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //r
                            n++;
                            value = "";
                            if (tbValue[m].r != 0)
                                value = tbValue[m].r.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //h
                            n++;
                            value = "";
                            if (tbValue[m].h != 0)
                                value = tbValue[m].h.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //n
                            n++;
                            value = "";
                            if (tbValue[m].n != 0)
                                value = tbValue[m].n.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Lx
                            n++;
                            value = "";
                            if (tbValue[m].Lx != 0)
                                value = tbValue[m].Lx.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //A
                            n++;
                            value = "";
                            if (tbValue[m].A != 0)
                                value = tbValue[m].A.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //B
                            n++;
                            value = "";
                            if (tbValue[m].B != 0)
                                value = tbValue[m].B.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //C
                            n++;
                            value = "";
                            if (tbValue[m].C != 0)
                                value = tbValue[m].C.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //D
                            n++;
                            value = "";
                            if (tbValue[m].D != 0)
                                value = tbValue[m].D.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Quantity
                            n++;
                            value = "";
                            if (tbValue[m].Quantity != 0)
                                value = tbValue[m].Quantity.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Length
                            n++;
                            value = "";
                            if (tbValue[m].Length != 0)
                                value = tbValue[m].Length.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value)); //获取i行j列数据
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalLength
                            n++;
                            value = "";
                            if (tbValue[m].TotalLength != 0)
                                value = tbValue[m].TotalLength.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //UnitWeight
                            n++;
                            value = "";
                            if (tbValue[m].UnitWeight != 0)
                                value = tbValue[m].UnitWeight.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalWeight
                            n++;
                            value = "";
                            if (tbValue[m].TotalWeight != 0)
                                value = tbValue[m].TotalWeight.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }
                            //if (tbValue[m].ShapeConfg.ToString().Contains("MO135"))
                            //    _blcName = "MO135";
                            //else 
                            if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
                                _blcName = "MO";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MUC"))
                                _blcName = "MUC";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MUR"))
                                _blcName = "MUR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MU"))
                                _blcName = "MU";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MSZR"))
                                _blcName = "MSZR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MSZ"))
                                _blcName = "MSZ";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXCR"))
                                _blcName = "MIXCR0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXC"))
                                _blcName = "MIXC0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXAR"))
                                _blcName = "MIXAR0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MIXA"))
                                _blcName = "MIXA0";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                _blcName = "MA";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCT"))
                                _blcName = "MCT";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCB"))
                                _blcName = "MCB";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCR"))
                                _blcName = "MCR";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MCL"))
                                _blcName = "MCL";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MLL"))
                                _blcName = "MLL";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("MLR"))
                                _blcName = "MLR";
                            db.CopyBlockFromFile(_dwgPath, _blcName);
                            //if (_blcName == "MLR" || _blcName == "MLL")
                            //    BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 16 * m + 8)), 1, _blcName, _dwgPath, 0);
                            //else
                              BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 16 * scale + 16 * m + 8)), 0.8, _blcName, _dwgPath, 0);

                        }
                        catch (Exception ex)
                        { }
                    }
                }

                #endregion

                #region 表格添加数据

                #endregion

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = 4 * 3 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 16 * 3 * scale;
                    else if (i == 3)
                        tb.Columns[i].Width = 11 * 3 * scale;
                    else if (i > headName.Count - 4)
                        tb.Columns[i].Width = 9 * 3 * scale;
                    else if (i > headName.Count - 6)
                        tb.Columns[i].Width = 8 * 3 * scale;
                    else
                        tb.Columns[i].Width = 4 * 3 * scale;
                }
                #endregion

                //行高
                for (int i = 2; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 16 * scale;
                }

                #region 列单元格合并

                ////合并数据定义
                //Dictionary<int, int> dic = new Dictionary<int, int>();
                //int rowIndex = 0;
                //int num = 0;
                //string stShape = tbValue[0].ShapeConfg.ToString();//要合并的类型
                //string stDia = tbValue[0].Diameter.ToString();//要合并的钢筋直径
                //for (int i = 0; i < tbValue.Count; ++i)
                //{
                //    //同样的直径和类型合并
                //    if (tbValue[i].ShapeConfg.ToString() == stShape&& tbValue[i].Diameter.ToString() == stDia)
                //    {
                //        num++;
                //    }
                //    else
                //    {

                //        dic.Add(rowIndex, num);
                //        num = 1;
                //        rowIndex = i;
                //        //下一条要合并的直径和类型
                //        stDia = tbValue[i].Diameter.ToString();
                //        stShape = tbValue[i].ShapeConfg.ToString();
                //    }
                //    if (i == tbValue.Count - 1)
                //        dic.Add(rowIndex, num);
                //}

                // 列单元格合并
                //int topRow = 2;

                //List<CellRange> cellList = new List<CellRange>();

                //foreach (KeyValuePair<int, int> pr in dic)
                //{
                //    curAllRow += pr.Value;
                //    lastMegerHeight = pr.Value * 6.5 * scale;
                //    tb.Cells[topRow, 2].Alignment = CellAlignment.MiddleCenter;
                //    if (pr.Value < 4)
                //    {
                //        for (int i = 0; i < pr.Value; i++)
                //        {
                //            tb.Rows[topRow+i].Height = intervalHeight / pr.Value;                            
                //        }
                //        cuRCount++;
                //        curAllRow -= pr.Value;
                //        lastMegerHeight =32 * scale;

                //    }

                //    db.CopyBlockFromFile(_dwgPath, _blcName);
                //    BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8*3 * scale, -(7 * scale + 12 * scale + intervalHeight * cuRCount+ 6.5  * curAllRow - lastMegerHeight * 0.4)), 1, _blcName, _dwgPath, 0);
                //    CellRange range = CellRange.Create(tb, topRow, 2, topRow + pr.Value - 1, 2);


                //    cellList.Add(range);
                //    topRow += pr.Value;

                //}
                //foreach (CellRange range in cellList)
                //{
                //    tb.MergeCells(range);
                //}

                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                #endregion

                #region 其他页

                #endregion
                tr.Commit();
                return tb;
            }
        }

       
        #endregion

        #region 分页
        public static void CalcPage(RebarCollection listRebar, double scale, ref List<RebarCollection> divDic)
        {
            Dictionary<int, int> dic = new Dictionary<int, int>();
            int cuRDivCount = 0;//当前页行高小于块高度的数量
            int curDivAllRow = 0;//当前页行数
            int rowIndex = 0;
            int num = 0;
            string stShape = listRebar[0].ShapeConfg.ToString();//要合并的类型
            string stDia = listRebar[0].Diameter.ToString();//要合并的钢筋直径
            for (int i = 0; i < listRebar.Count; ++i)
            {
                //同样的直径和类型合并
                if (listRebar[i].ShapeConfg.ToString() == stShape && listRebar[i].Diameter.ToString() == stDia)
                {
                    num++;
                }
                else
                {

                    dic.Add(rowIndex, num);
                    num = 1;
                    rowIndex = i;
                    //下一条要合并的直径和类型
                    stDia = listRebar[i].Diameter.ToString();
                    stShape = listRebar[i].ShapeConfg.ToString();
                }
                if (i == listRebar.Count - 1)
                    dic.Add(rowIndex, num);
            }
            int lastDivAllRow = 0;
            int allRow = 0;
            int calNum = 0;
            foreach (KeyValuePair<int, int> pr in dic)
            {
                calNum++;
                allRow += pr.Value;
                curDivAllRow += pr.Value;
                lastMegerHeight = pr.Value * 6.5 * scale;
                if (pr.Value < 4)
                {
                    cuRDivCount++;
                    curDivAllRow -= pr.Value;
                    lastMegerHeight = 32 * scale;

                }
                tbH = 7 * scale + 12 * scale + intervalHeight * cuRDivCount + 6.5 * curDivAllRow;
                if (tbH > A3Height)
                {
                    RebarCollection div = new RebarCollection();
                    for (int i = lastDivAllRow; i < allRow - pr.Value; i++)
                    {
                        div.Add(listRebar[i]);
                    }
                    //分页
                    divDic.Add(div);
                    lastDivAllRow = allRow - pr.Value;
                    tbH = 0;
                    cuRDivCount = 1;
                    curDivAllRow = pr.Value;
                    //计算下一分组是否超尺寸
                    tbH = 7 * scale + 12 * scale + intervalHeight * cuRDivCount + 6.5 * curDivAllRow;
                    if (tbH > A3Height)
                    {
                        div = new RebarCollection();
                        for (int i = lastDivAllRow; i < allRow; i++)
                        {
                            div.Add(listRebar[i]);
                        }
                        //分页
                        divDic.Add(div);
                        lastDivAllRow = allRow;
                        tbH = 0;
                        cuRDivCount = 0;
                        curDivAllRow = 0;
                        if (calNum == dic.Count)
                        {
                            div = new RebarCollection();
                            for (int i = lastDivAllRow; i < allRow; i++)
                            {
                                div.Add(listRebar[i]);
                            }
                            //分页
                            divDic.Add(div);
                        }
                    }
                    if (calNum == dic.Count)
                    {
                        div = new RebarCollection();
                        for (int i = lastDivAllRow; i < allRow; i++)
                        {
                            div.Add(listRebar[i]);
                        }
                        //分页
                        divDic.Add(div);
                    }
                }
                else
                {
                    if (calNum == dic.Count)
                    {
                        RebarCollection div = new RebarCollection();
                        for (int i = lastDivAllRow; i < allRow; i++)
                        {
                            div.Add(listRebar[i]);
                        }
                        //分页
                        divDic.Add(div);
                    }
                }
            }
        }

        public static void CalcCloumPage(RebarCollection listRebar, double scale, ref List<RebarCollection> divDic)
        {
            RebarCollection div = new RebarCollection();
            RebarCollection div1 = new RebarCollection();
            for (int i = 0; i < listRebar.Count; ++i)
            {
                //同样的直径和类型合并
                if (listRebar[i].MBarMark < 6)
                {
                    if (i < 13)
                        div.Add(listRebar[i]);
                    else
                        div1.Add(listRebar[i]);
                }
                else
                {
                    div1.Add(listRebar[i]);

                }

            }
            divDic.Add(div);
            if (div1.Count > 0)
                divDic.Add(div1);
        }
        /// <summary>
        /// 墩柱分页
        /// </summary>
        /// <param name="listRebar"></param>
        /// <param name="scale"></param>
        /// <param name="divDic"></param>
        public static void CalcCloumPageNew(RebarCollection listRebar, double scale, ref List<RebarCollection> divDic)
        {
            //int num = listRebar.Count+5 / 13;
            RebarCollection div = new RebarCollection();
            int no = 0;
            for (int i = 0; i < listRebar.Count; ++i)
            {
                //同样的直径和类型合并
                if (i < 13 * (no + 1))
                    div.Add(listRebar[i]);
                else
                {
                    divDic.Add(div);
                    div = new RebarCollection();
                    div.Add(listRebar[i]);
                    no++;
                }
            }
            if (div.Count > 0)
                divDic.Add(div);
        }
        /// <summary>
        /// 盖梁分页
        /// </summary>
        /// <param name="listRebar"></param>
        /// <param name="scale"></param>
        /// <param name="divDic"></param>
        public static void CalcBeamPage(RebarCollection listRebar, double scale, ref List<RebarCollection> divDic)
        {
            RebarCollection div = new RebarCollection();
            int num = 0;
            for (int i = 0; i < listRebar.Count; ++i)
            {
                //同样的直径和类型合并
                if (num < 13)
                {
                    div.Add(listRebar[i]);
                    num++;

                }
                else
                {
                    divDic.Add(div);
                    div = new RebarCollection();
                    num = 1;
                    div.Add(listRebar[i]);
                }
            }
            divDic.Add(div);

        }
        #endregion

  
    }

    public class PierFootData
    {
        public string PierNo { get; set; }
        public string Station { get; set; }
        public string FootType { get; set; }
        public string ColumnType { get; set; }
        public string ColumnHeight { get; set; }
        public double TopFoot { get; set; }
        public double H { get; set; }
        public double FootingType { get; set; }
        public double para1 { get; set; }
        public double para2 { get; set; }
        public double para3 { get; set; }
    }
}
